Convert the telegraf_plugins_extra varaible to a hash so that we can merge the hashes of multiple var files

This commit is contained in:
Troy Jendra
2018-05-06 16:54:34 +10:00
parent 2f3b11241d
commit 51ac4b7640
4 changed files with 29 additions and 29 deletions

View File

@ -70,7 +70,7 @@ The config will be printed line by line into the configuration, so you could als
and it will be printed in the configuration file. and it will be printed in the configuration file.
There are two properties which are the same, but are used differently. Those are: There are two properties which are similar, but are used differently. Those are:
* `telegraf_plugins_default` * `telegraf_plugins_default`
* `telegraf_plugins_extra` * `telegraf_plugins_extra`
@ -90,11 +90,11 @@ With the property `telegraf_plugins_default` it is set to use the default set of
Every telegraf agent has these as a default configuration. Every telegraf agent has these as a default configuration.
The 2nd parameter `telegraf_plugins_extra` can be used to add plugins specific to the servers goal. Following is an example for using this parameter for MySQL database servers: The 2nd parameter `telegraf_plugins_extra` can be used to add plugins specific to the servers goal. It is a hash instead of a list, so that you can merge values from multiple var files together. Following is an example for using this parameter for MySQL database servers:
cat group_vars/mysql_database cat group_vars/mysql_database
telegraf_plugins_extra: telegraf_plugins_extra:
- plugin: mysql mysql:
config: config:
- servers = ["root:{{ mysql_root_password }}@tcp(localhost:3306)/"] - servers = ["root:{{ mysql_root_password }}@tcp(localhost:3306)/"]

View File

@ -46,7 +46,7 @@ telegraf_plugins_default:
- plugin: kernel - plugin: kernel
# extra configuration - /etc/telegraf/telegraf.d/* # extra configuration - /etc/telegraf/telegraf.d/*
telegraf_plugins_extra: [] telegraf_plugins_extra: {}
# RedHat specific settings for convenience # RedHat specific settings for convenience
telegraf_redhat_releasever: "$releasever" telegraf_redhat_releasever: "$releasever"

View File

@ -38,11 +38,11 @@
- name: "Copy telegraf extra plugins" - name: "Copy telegraf extra plugins"
template: template:
src: "telegraf-extra-plugin.conf.j2" src: "telegraf-extra-plugin.conf.j2"
dest: "/etc/telegraf/telegraf.d/{{ item.filename | default(item.plugin) }}.conf" dest: "/etc/telegraf/telegraf.d/{{ item.value.filename | default(item.key) }}.conf"
owner: telegraf owner: telegraf
group: telegraf group: telegraf
mode: 0640 mode: 0640
with_items: "{{ telegraf_plugins_extra }}" with_dict: "{{ telegraf_plugins_extra }}"
when: "telegraf_plugins_extra is defined and telegraf_plugins_extra is iterable" when: "telegraf_plugins_extra is defined and telegraf_plugins_extra is iterable"
become: yes become: yes
notify: "Restart Telegraf" notify: "Restart Telegraf"

View File

@ -1,47 +1,47 @@
### MANAGED BY {{ role_path|basename }} ANSIBLE ROLE ### ### MANAGED BY {{ role_path|basename }} ANSIBLE ROLE ###
[[inputs.{{ item.plugin }}]] [[inputs.{{ item.key }}]]
{% if item.interval is defined %} {% if item.value.interval is defined %}
interval = "{{ item.interval }}s" interval = "{{ item.value.interval }}s"
{% endif %} {% endif %}
{% if item.config is defined and item.config is iterable %} {% if item.value.config is defined and item.value.config is iterable %}
{% for items in item.config %} {% for items in item.value.config %}
{{ items }} {{ items }}
{% endfor %} {% endfor %}
{% endif %} {% endif %}
{% if item.tags is defined and item.tags is iterable %} {% if item.value.tags is defined and item.value.tags is iterable %}
[inputs.{{ item.plugin }}.tags] [inputs.{{ item.key }}.tags]
{% for items in item.tags %} {% for items in item.value.tags %}
{{ items }} {{ items }}
{% endfor %} {% endfor %}
{% endif %} {% endif %}
{% if item.tagpass is defined and item.tagpass is iterable %} {% if item.value.tagpass is defined and item.value.tagpass is iterable %}
[{{ item.plugin }}.tagpass] [{{ item.key }}.tagpass]
{% for items in item.tagpass %} {% for items in item.value.tagpass %}
{{ items }} {{ items }}
{% endfor %} {% endfor %}
{% endif %} {% endif %}
{% if item.tagdrop is defined and item.tagdrop is iterable %} {% if item.value.tagdrop is defined and item.value.tagdrop is iterable %}
[{{ item.plugin }}.tagdrop] [{{ item.key }}.tagdrop]
{% for items in item.tagdrop %} {% for items in item.value.tagdrop %}
{{ items }} {{ items }}
{% endfor %} {% endfor %}
{% endif %} {% endif %}
{% if item.pass is defined and item.pass is iterable %} {% if item.value.pass is defined and item.value.pass is iterable %}
[{{ item.plugin }}.pass] [{{ item.key }}.pass]
{% for items in item.pass %} {% for items in item.value.pass %}
{{ items }} {{ items }}
{% endfor %} {% endfor %}
{% endif %} {% endif %}
{% if item.drop is defined and item.drop is iterable %} {% if item.value.drop is defined and item.value.drop is iterable %}
[{{ item.plugin }}.drop] [{{ item.key }}.drop]
{% for items in item.drop %} {% for items in item.value.drop %}
{{ items }} {{ items }}
{% endfor %} {% endfor %}
{% endif %} {% endif %}
{% if item.specifications is defined and item.specifications is iterable %} {% if item.value.specifications is defined and item.value.specifications is iterable %}
[[{{item.plugin}}.specifications]] [[{{item.key}}.specifications]]
{% for items in item.specifications %} {% for items in item.value.specifications %}
{{ items }} {{ items }}
{% endfor %} {% endfor %}
{% endif %} {% endif %}