From ec993c2066ab3be2f676f9d969c70d6ff70ba914 Mon Sep 17 00:00:00 2001 From: Werner Dijkerman Date: Wed, 13 Jan 2016 15:50:54 +0100 Subject: [PATCH] Made it work with telegraf 0.10.0 --- .gitignore | 1 + defaults/main.yml | 10 ++- tasks/main.yml | 18 +++++- templates/telegraf.conf.j2 | 123 +++++++++++++++++++++++++++++++++++++ 4 files changed, 148 insertions(+), 4 deletions(-) create mode 100644 templates/telegraf.conf.j2 diff --git a/.gitignore b/.gitignore index 26b9544..7529331 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .kitchen/ .kitchen.local.yml .idea/ +pmip diff --git a/defaults/main.yml b/defaults/main.yml index 8c4385f..fd13958 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,17 +1,21 @@ --- # defaults file for ansible-telegraf -telegraf_agent_version: 0.2.0 -telegraf_agent_interval: 10 +telegraf_agent_version: 0.10.0 +telegraf_agent_interval: 60 telegraf_agent_debug: False +telegraf_agent_round_interval: True +telegraf_agent_flush_interval: 10 +telegraf_agent_flush_jitter: 0 telegraf_agent_tags: telegraf_agent_output: - type: influxdb config: - - url = "http://localhost:8086" + - urls = ["http://localhost:8086"] - database = "telegraf" + - precision = "s" telegraf_plugins_default: - plugin: cpu diff --git a/tasks/main.yml b/tasks/main.yml index c97e86e..6efe3d8 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -9,12 +9,28 @@ include: "Debian.yml" when: ansible_os_family == "Debian" -- name: "Copy the template" +- name: "Set fact by remove the dots from version" + action: 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 + 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 + when: telegraf_ver >= 100 sudo: yes notify: "Restart Telegraf" diff --git a/templates/telegraf.conf.j2 b/templates/telegraf.conf.j2 new file mode 100644 index 0000000..ad0a57f --- /dev/null +++ b/templates/telegraf.conf.j2 @@ -0,0 +1,123 @@ +# Telegraf configuration + +[tags] +{% if telegraf_agent_tags is defined and telegraf_agent_tags is iterable %} +{% for item in telegraf_agent_tags %} + {{ item.tag_name }} = "{{ item.tag_value }}" +{% endfor %} +{% endif %} + +# Configuration for telegraf agent +[agent] + interval = "{{ telegraf_agent_interval }}s" + debug = {{ telegraf_agent_debug | lower }} + hostname = "{{ ansible_fqdn }}" + round_interval = {{ telegraf_agent_round_interval | lower }} + flush_interval = "{{ telegraf_agent_flush_interval }}s" + flush_jitter = "{{ telegraf_agent_flush_jitter }}s" + +############################################################################### +# OUTPUTS # +############################################################################### + +{% if telegraf_agent_output is defined and telegraf_agent_output is iterable %} +{% for item in telegraf_agent_output %} +[[outputs.{{ item.type }}]] +{% for items in item.config %} + {{ items }} +{% endfor %} +{% endfor %} +{% endif %} + +############################################################################### +# INPUTS # +############################################################################### + +{% if telegraf_plugins_default is defined and telegraf_plugins_default is iterable %} +{% for item in telegraf_plugins_default %} +[[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 %} + + +{% 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