diff --git a/roles/collectd/defaults/main.yml b/roles/collectd/defaults/main.yml index 747cdfc..071845c 100644 --- a/roles/collectd/defaults/main.yml +++ b/roles/collectd/defaults/main.yml @@ -6,3 +6,5 @@ collectd_network_listen: [] collectd_disable_plugins: [] collectd_df: {} + +collectd_load_unixsock_plugin: true diff --git a/roles/collectd/files/collectd-runtime-dir.conf b/roles/collectd/files/collectd-runtime-dir.conf new file mode 100644 index 0000000..9a6cc48 --- /dev/null +++ b/roles/collectd/files/collectd-runtime-dir.conf @@ -0,0 +1,2 @@ +[Service] +RuntimeDirectory=collectd diff --git a/roles/collectd/handlers/main.yml b/roles/collectd/handlers/main.yml index 8c93f7a..4b1e28e 100644 --- a/roles/collectd/handlers/main.yml +++ b/roles/collectd/handlers/main.yml @@ -1,3 +1,8 @@ +- name: reload systemd + systemd: + daemon_reload: true + changed_when: true + - name: restart collectd service: name: collectd diff --git a/roles/collectd/tasks/main.yml b/roles/collectd/tasks/main.yml index e90d1ac..faf8dd9 100644 --- a/roles/collectd/tasks/main.yml +++ b/roles/collectd/tasks/main.yml @@ -23,6 +23,16 @@ tags: - collectd-config +- name: ensure collectd unixsock plugin is configured + template: + src: collectd-unixsock.conf.j2 + dest: /etc/collectd.d/unixsock.conf + mode: 'u=rw,go=r' + notify: restart collectd + tags: + - collectd-config + - collectd-unixsock + - name: ensure collectd network plugin is configured template: src: collectd-network.conf.j2 @@ -44,6 +54,20 @@ - collectd-config - collectd-processes +- name: ensure collectd systemd unit extension directory exists + file: + path: /etc/systemd/system/collectd.service.d + mode: 'u=rwx,go=rx' + state: directory +- name: ensure collectd.service runtime directory is configured + copy: + src: collectd-runtime-dir.conf + dest: /etc/systemd/system/collectd.service.d/runtime-dir.conf + mode: 'u=rw,go=r' + notify: + - reload systemd + - restart collectd + - name: ensure collectd starts at boot service: name: collectd diff --git a/roles/collectd/templates/collectd-unixsock.conf.j2 b/roles/collectd/templates/collectd-unixsock.conf.j2 new file mode 100644 index 0000000..a83b15b --- /dev/null +++ b/roles/collectd/templates/collectd-unixsock.conf.j2 @@ -0,0 +1,18 @@ +{% if collectd_load_unixsock_plugin %} +LoadPlugin unixsock +{% endif %} + + + SocketFile "/run/collectd/socket" +{% if collectd_unixsock_group|d %} + SocketGroup "{{ collectd_unixsock_group }}" +{% endif %} +{% if collectd_unixsock_perms|d %} + SocketPerms "{{ collectd_unixsock_perms }}" +{% endif %} +{% if collectd_unixsock_delete|d is true %} + DeleteSocket true +{% elif collectd_unix_sock_delete|d is false%} + DeleteSocket false +{% endif %} +