linux - Collectd 无法读取 Ansible 发送的配置文件
问题描述
我目前正在使用 Ansible 自动设置 collectd。除了配置文件传输外,一切都按预期进行。
每次我将带有 Ansible 的 collectd 配置文件发送到我的 collectd 服务器时,都会出现以下错误。
Parse error in file `/etc/collectd.conf', line 23 near `': syntax error, unexpected $end
此问题已在“配置文件发现意外 $end,不确定原因”中得到处理。
根据我在那里找到的答案,我应该在文件末尾放置一个新行。每次我尝试都会发生同样的错误......
但是,当我在 collectd 服务器上手动重新保存文件时,它确实可以工作。有谁知道这是什么原因以及如何解决?配置文件需要由 Ansible 发送。
Linux CentOS 7
Collectd 版本 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 文件的语法。我可以打开文件,再次保存它们而不做任何更改,它们就可以工作了。但是,如果您真的想查看这些插件配置文件的代码,您可以在此处找到它们。
提前致谢!
解决方案
显然,之前发布的问题的答案确实是我的问题的答案。需要在我的每个配置文件的末尾添加一个空行。
推荐阅读
- python - 嵌入 PYQT5 框架时无人机(DJI Tello)相机不工作
- python - R中允许的最大功能数量是多少?收到“堆栈溢出”错误消息
- graphql - 如何考虑联合服务
- javascript - 在实现重力和地面 y 变量的同时,我将如何进行 gif 跳转?
- python - Telegraph API 中的格式化列表
- c# - 随机数组未正确写入文件
- python - 在 slurm 工作中的时间睡眠
- javascript - 如何防止每次输入后触发选择事件?
- azure - 将邮件移动到垃圾文件夹时,客户端桌面版和 Web 版之间行为不同的 Outlook 加载项
- python - 熊猫:to.datetime() 问题