From 042c877fa39fda18c0a8391ea38e5367ab8096b4 Mon Sep 17 00:00:00 2001
From: Adar Nimrod <nimrod@shore.co.il>
Date: Wed, 16 Dec 2015 10:35:18 +0200
Subject: [PATCH] More work on Collectd, stil WIP.

---
 tasks/collectd_agent.yml         | 27 ++++++++++++++++++++++++---
 templates/collectd/write.conf.j2 |  9 +++++++++
 2 files changed, 33 insertions(+), 3 deletions(-)
 create mode 100644 templates/collectd/write.conf.j2

diff --git a/tasks/collectd_agent.yml b/tasks/collectd_agent.yml
index 4de14b8..31eb7fa 100644
--- a/tasks/collectd_agent.yml
+++ b/tasks/collectd_agent.yml
@@ -23,16 +23,37 @@
   file:
     path: /etc/collectd/collectd.conf.d/
     owner: root
-    group: root
+    group: '{{ root_group[ansible_os_family] }}'
     mode: '0755'
     state: directory
 
-- name: Base configuration
+- name: Gather Collectd facts
+  collectd_facts:
+
+- name: Base Collectd configuration
   copy:
     src: collectd.conf
     dest: /etc/collectd/collectd.conf
     owner: root
-    group: root
+    group: '{{ root_group[ansible_os_family] }}'
+    mode: '0644'
+  notify:
+  - Restart Collectd
+
+- name: Default Collectd configuration
+  with_fileglob:
+  - template/collectd/*.j2
+  template:
+    src: '{{ item }}'
+    dest: /etc/collectd/collectd.conf.d/
+    owner: root
+    group: '{{ root_group[ansible_os_family] }}'
     mode: '0644'
   notify:
   - Restart Collectd
+
+- name: Enabled Collectd service
+  service:
+    name: collectd
+    state: started
+    enabled: yes
diff --git a/templates/collectd/write.conf.j2 b/templates/collectd/write.conf.j2
new file mode 100644
index 0000000..a232ac8
--- /dev/null
+++ b/templates/collectd/write.conf.j2
@@ -0,0 +1,9 @@
+{% if collectd_collectd_server is defined %}
+
+{% elif collectd_riemann_server is defined and (collectd['major'] > 5 or
+(collectd['major'] == 5 and collectd['minor'] >= 3)) %}
+
+{% elif collectd_graphite_server is defined and (collectd['major'] > 5 or
+(collectd['major'] == 5 and collectd['minor'] >= 1)) %}
+
+{% endif %}
-- 
GitLab