我目前正在使用Ansible自动化收集的设置。 除了配置文件传输,一切都按预期进行。
每次我将使用Ansible收集的配置文件发送到收集的服务器时,都会出现以下错误。
Parse error in file `/etc/collectd.conf', line 23 near `': syntax error, unexpected $end
此问题已在“ Config file finding unexpected $end, not sure why”中处理。
根据我在那里找到的答案,我应该在文件末尾放置新行。每次我尝试发生相同的错误...
但是,当我手动将文件重新保存到收集的服务器上时,它确实可以工作。有谁知道这是什么原因以及如何解决?配置文件需要由Ansible发送。
Linux CentOS 7
收集了版本5.8.1
MacOS Mojave 10.14.3
Ansible版本2.7.9
Ansible代码:tasks / configuration.yml
---
- name: Install main configuration file
template:
src: collectd.conf.j2
dest: "{{ collectd_config_file }}"
owner: root
group: root
mode: 0644
force: yes
notify: restart collectd
tags: collectd
- name: Install interface configuration file
template:
src: interface.conf.j2
dest: "{{ collectd_include_dir }}/interface.conf"
owner: root
group: root
mode: 0644
force: yes
notify: restart collectd
tags: collectd
- name: Install snmp configuration file
template:
src: snmp.conf.j2
dest: "{{ collectd_include_dir }}/snmp.conf"
owner: root
group: root
mode: 0644
force: yes
notify: restart collectd
tags: collectd
- name: Install write_graphite configuration file
template:
src: write_graphite.conf.j2
dest: "{{ collectd_include_dir }}/write_graphite.conf"
owner: root
group: root
mode: 0644
force: yes
notify: restart collectd
tags: collectd
Ansible代码:templates / collectd.conf.j2
Hostname "localhost"
FQDNLookup true
#BaseDir "/var/lib/collectd"
#PIDFile "/var/run/collectd.pid"
#PluginDir "/usr/lib64/collectd"
#TypesDB "/usr/share/collectd/types.db"
#AutoLoadPlugin false
#CollectInternalStats false
#Interval 10
#MaxReadInterval 86400
#Timeout 2
#ReadThreads 5
#WriteThreads 5
#WriteQueueLimitHigh 1000000
#WriteQueueLimitLow 800000
LoadPlugin syslog
<Plugin syslog>
LogLevel info
</Plugin>
LoadPlugin interface
LoadPlugin snmp
LoadPlugin write_graphite
Include "/etc/collectd.d/*.conf"
错误输出:
localhost.localdomain collectd[19021]: Parse error in file `/etc/collectd.conf', line 23 near `': syntax error, unexpected $end
localhost.localdomain collectd[19021]: yyparse returned error #1
localhost.localdomain collectd[19021]: configfile: Cannot read file `/etc/collectd.conf'.
localhost.localdomain collectd[19021]: Unable to read config file /etc/collectd.conf.
localhost.localdomain collectd[19021]: Error: Reading the config file failed!
localhost.localdomain collectd[19021]: Read the logs for details.
localhost.localdomain systemd[1]: collectd.service: main process exited, code=exited, status=1/FAILURE
localhost.localdomain systemd[1]: Failed to start Collectd statistics daemon.
问题不在于/etc/collectd.d/*.conf文件的语法中。我可以打开文件,然后再次保存而不做任何更改,它们将起作用。但是,如果您确实希望查看这些插件配置文件的代码,则可以找到它们here。
谢谢!