From cf37fb1d2e1bd40d8e9fd6b3f0cae5f86aac8d33 Mon Sep 17 00:00:00 2001 From: Steven Wirges Date: Wed, 6 Apr 2016 16:11:48 +0200 Subject: [PATCH 1/2] moved extra plugins to extra configs in telegraf.d and changed the main.yml to more yml stylish definitions --- tasks/main.yml | 40 +++++++++++------- templates/etc-opt-telegraf-telegraf.conf.j2 | 45 --------------------- templates/telegraf-extra-plugin.conf.j2 | 0 templates/telegraf.conf.j2 | 45 --------------------- 4 files changed, 26 insertions(+), 104 deletions(-) create mode 100644 templates/telegraf-extra-plugin.conf.j2 diff --git a/tasks/main.yml b/tasks/main.yml index 6efe3d8..55b14eb 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -10,27 +10,39 @@ when: ansible_os_family == "Debian" - name: "Set fact by remove the dots from version" - action: set_fact - telegraf_ver="{{ telegraf_agent_version.replace('.','') }}" + set_fact: + telegraf_ver: "{{ telegraf_agent_version.replace('.','') }}" - name: "Copy the template for versions < 0.10.0" - action: template - src=etc-opt-telegraf-telegraf.conf.j2 - dest=/etc/opt/telegraf/telegraf.conf - owner=root - group=root - mode=644 + template: + src: etc-opt-telegraf-telegraf.conf.j2 + dest: /etc/opt/telegraf/telegraf.conf + owner: root + group: root + mode: 644 when: telegraf_ver < 100 sudo: yes notify: "Restart Telegraf" - name: "Copy the template for versions >= 0.10.0" - action: template - src=telegraf.conf.j2 - dest=/etc/telegraf/telegraf.conf - owner=root - group=root - mode=644 + template: + src: telegraf.conf.j2 + dest: /etc/telegraf/telegraf.conf + owner: root + group: root + mode: 644 when: telegraf_ver >= 100 sudo: yes notify: "Restart Telegraf" + +- name: "Copy telegraf extra plugins" + template: + src: "telegraf.conf.j2" + dest: "/etc/telegraf/telegraf.d/{{ item.plugin }}.conf" + owner: root + group: root + mode: 644 + with_items: "{{ telegraf_plugins_extra }}" + when: "telegraf_plugins_extra is defined and telegraf_plugins_extra is iterable" + sudo: yes + notify: "Restart Telegraf" \ No newline at end of file diff --git a/templates/etc-opt-telegraf-telegraf.conf.j2 b/templates/etc-opt-telegraf-telegraf.conf.j2 index 57a0f1c..cb58fc1 100644 --- a/templates/etc-opt-telegraf-telegraf.conf.j2 +++ b/templates/etc-opt-telegraf-telegraf.conf.j2 @@ -68,50 +68,5 @@ {% endif %} -{% endfor %} -{% endif %} - -{% if telegraf_plugins_extra is defined and telegraf_plugins_extra is iterable %} -{% for item in telegraf_plugins_extra %} -[{{ item.plugin }}] -{% if item.interval is defined %} - interval = "{{ item.interval }}s" -{% endif %} -{% if item.config is defined and item.config is iterable %} -{% for items in item.config %} - {{ items }} -{% endfor %} -{% endif %} -{% if item.tagpass is defined and item.tagpass is iterable %} -[{{ item.plugin }}.tagpass] -{% for items in item.tagpass %} - {{ items }} -{% endfor %} -{% endif %} -{% if item.tagdrop is defined and item.tagdrop is iterable %} -[{{ item.plugin }}.tagdrop] -{% for items in item.tagdrop %} - {{ items }} -{% endfor %} -{% endif %} -{% if item.pass is defined and item.pass is iterable %} -[{{ item.plugin }}.pass] -{% for items in item.pass %} - {{ items }} -{% endfor %} -{% endif %} -{% if item.drop is defined and item.drop is iterable %} -[{{ item.plugin }}.drop] -{% for items in item.drop %} - {{ items }} -{% endfor %} -{% endif %} -{% if item.specifications is defined and item.specifications is iterable %} -[[{{item.plugin}}.specifications]] -{% for items in item.specifications %} - {{ items }} -{% endfor %} -{% endif %} - {% endfor %} {% endif %} diff --git a/templates/telegraf-extra-plugin.conf.j2 b/templates/telegraf-extra-plugin.conf.j2 new file mode 100644 index 0000000..e69de29 diff --git a/templates/telegraf.conf.j2 b/templates/telegraf.conf.j2 index ad0a57f..0de4348 100644 --- a/templates/telegraf.conf.j2 +++ b/templates/telegraf.conf.j2 @@ -75,49 +75,4 @@ {% endfor %} {% endif %} {% endfor %} -{% endif %} - - -{% if telegraf_plugins_extra is defined and telegraf_plugins_extra is iterable %} -{% for item in telegraf_plugins_extra %} -[[inputs.{{ item.plugin }}]] -{% if item.interval is defined %} - interval = "{{ item.interval }}s" -{% endif %} -{% if item.config is defined and item.config is iterable %} -{% for items in item.config %} - {{ items }} -{% endfor %} -{% endif %} -{% if item.tagpass is defined and item.tagpass is iterable %} -[{{ item.plugin }}.tagpass] -{% for items in item.tagpass %} - {{ items }} -{% endfor %} -{% endif %} -{% if item.tagdrop is defined and item.tagdrop is iterable %} -[{{ item.plugin }}.tagdrop] -{% for items in item.tagdrop %} - {{ items }} -{% endfor %} -{% endif %} -{% if item.pass is defined and item.pass is iterable %} -[{{ item.plugin }}.pass] -{% for items in item.pass %} - {{ items }} -{% endfor %} -{% endif %} -{% if item.drop is defined and item.drop is iterable %} -[{{ item.plugin }}.drop] -{% for items in item.drop %} - {{ items }} -{% endfor %} -{% endif %} -{% if item.specifications is defined and item.specifications is iterable %} -[[{{item.plugin}}.specifications]] -{% for items in item.specifications %} - {{ items }} -{% endfor %} -{% endif %} -{% endfor %} {% endif %} \ No newline at end of file From 01d05b0a88ce6de56aed8cd4ef06db1b0afbe982 Mon Sep 17 00:00:00 2001 From: Steven Wirges Date: Thu, 23 Jun 2016 12:56:59 +0200 Subject: [PATCH 2/2] added template for extra plugins --- tasks/main.yml | 2 +- templates/telegraf-extra-plugin.conf.j2 | 44 +++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/tasks/main.yml b/tasks/main.yml index 55b14eb..46007ea 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -37,7 +37,7 @@ - name: "Copy telegraf extra plugins" template: - src: "telegraf.conf.j2" + src: "telegraf-extra-plugin.conf.j2" dest: "/etc/telegraf/telegraf.d/{{ item.plugin }}.conf" owner: root group: root diff --git a/templates/telegraf-extra-plugin.conf.j2 b/templates/telegraf-extra-plugin.conf.j2 index e69de29..c6f90b0 100644 --- a/templates/telegraf-extra-plugin.conf.j2 +++ b/templates/telegraf-extra-plugin.conf.j2 @@ -0,0 +1,44 @@ + +{% if telegraf_plugins_extra is defined and telegraf_plugins_extra is iterable %} +{% for item in telegraf_plugins_extra %} +[[inputs.{{ item.plugin }}]] +{% if item.interval is defined %} + interval = "{{ item.interval }}s" +{% endif %} +{% if item.config is defined and item.config is iterable %} +{% for items in item.config %} + {{ items }} +{% endfor %} +{% endif %} +{% if item.tagpass is defined and item.tagpass is iterable %} +[{{ item.plugin }}.tagpass] +{% for items in item.tagpass %} + {{ items }} +{% endfor %} +{% endif %} +{% if item.tagdrop is defined and item.tagdrop is iterable %} +[{{ item.plugin }}.tagdrop] +{% for items in item.tagdrop %} + {{ items }} +{% endfor %} +{% endif %} +{% if item.pass is defined and item.pass is iterable %} +[{{ item.plugin }}.pass] +{% for items in item.pass %} + {{ items }} +{% endfor %} +{% endif %} +{% if item.drop is defined and item.drop is iterable %} +[{{ item.plugin }}.drop] +{% for items in item.drop %} + {{ items }} +{% endfor %} +{% endif %} +{% if item.specifications is defined and item.specifications is iterable %} +[[{{item.plugin}}.specifications]] +{% for items in item.specifications %} + {{ items }} +{% endfor %} +{% endif %} +{% endfor %} +{% endif %} \ No newline at end of file