linuxmacosansiblecollectd

Collectd unable to read config files sent by Ansible


I am currently automating the setup of collectd with Ansible. Everything goes as expected except the configuration file transfer.

Every time I send collectd configuration files with Ansible to my collectd server it get following error.

Parse error in file `/etc/collectd.conf', line 23 near `': syntax error, unexpected $end

This problem was handled in "Config file finding unexpected $end, not sure why".

According to the answer I found there I should place a new line at the end of the file. Every time I try that the same error occurs...

However when I manually re-save the file on the collectd server it does work. Does anyone know what the cause of this is and how to solve it? The configuration files need to be sent by Ansible.

Linux CentOS 7
Collectd version 5.8.1

MacOS Mojave 10.14.3
Ansible version 2.7.9

Ansible code: 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 code: 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"



Error output:

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.

The problem doesn't lay in the syntax of the /etc/collectd.d/*.conf files. I can just open the files, save them again without any changes and they will work. If however you really want to see the code of those Plugin configuration files you can find them here.

Thanks in advance!


Solution

  • Apparently the answer to the previously posted question was indeed the answer to my question. An empty line needed to be added at the end of each of my configuration files.