diff --git a/roles/dj-wasabi.telegraf/.github/ISSUE_TEMPLATE/bug_report.md b/roles/dj-wasabi.telegraf/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 00000000..03201270 --- /dev/null +++ b/roles/dj-wasabi.telegraf/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,35 @@ +--- +name: Bug report +about: Help to improve this Ansible role. + +--- + +**Describe the bug** + + +**Installation method/version** + + +* Github / latest +* Ansible Galaxy / 1.1.0 + +**Ansible Version** + +``` + +``` + +**Targetted hosts** +Concerns the following OS(es): + + +* Ubuntu +* Debian +* CentOS +* Mint + +**Expected behavior** + + +**Additional context** + diff --git a/roles/dj-wasabi.telegraf/.github/ISSUE_TEMPLATE/feature_request.md b/roles/dj-wasabi.telegraf/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 00000000..08c83431 --- /dev/null +++ b/roles/dj-wasabi.telegraf/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,14 @@ +--- +name: Feature request +about: Suggest an idea for this Ansible role + +--- + +**Is your feature request related to a problem? Please describe.** +A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + +**Describe the solution you'd like** +A clear and concise description of what you want to happen. + +**Additional context** +Add any other context or screenshots about the feature request here. diff --git a/roles/dj-wasabi.telegraf/.travis.yml b/roles/dj-wasabi.telegraf/.travis.yml index 783ded38..86a0c657 100644 --- a/roles/dj-wasabi.telegraf/.travis.yml +++ b/roles/dj-wasabi.telegraf/.travis.yml @@ -5,7 +5,7 @@ services: - docker install: - - pip install molecule ansible docker + - pip install -r requirements.txt script: - molecule --version diff --git a/roles/dj-wasabi.telegraf/CHANGELOG.md b/roles/dj-wasabi.telegraf/CHANGELOG.md index 7c1bb675..d9d022c8 100644 --- a/roles/dj-wasabi.telegraf/CHANGELOG.md +++ b/roles/dj-wasabi.telegraf/CHANGELOG.md @@ -5,6 +5,25 @@ Below an overview of all changes in the releases. Version (Release date) +0.10.0 (2018-08-12) + + * Updating to telegraf 1.7.3 + * Fix Deprecation warnings #54 + * Changed 'include' to 'include_tasks' to remove deprecation warning #53 (By pull request: tjend (Thanks!)) + * Add option to remove extra plugin config files #52 (By pull request: tjend (Thanks!)) + * Plugins extra hash allow multiple inputs same type #50 (By pull request: tjend (Thanks!)) + * Using specific version for tests + * Update minimum Ansible version to 2.4 + +0.9.0 (2018-05-06) + + * plugins: be able to specify the filename of extra plugings #40 (By pull request: gaelL (Thanks!)) + * Fix markdown #41 (By pull request: Angristan (Thanks!)) + * Allow to override RedHat release version #43 (By pull request: tszym (Thanks!)) + * Improved comments, split up role, moved tags and added defaults #45 (By pull request: boxrick (Thanks!)) + * Fix Travis Tests #42 + * Convert the telegraf_plugins_extra varaible to a hash so that we can … #46 (By pull request: tjend (Thanks!)) + 0.8.0 (2017-10-30) * Updating to Molecule V2 diff --git a/roles/dj-wasabi.telegraf/CODE_OF_CONDUCT.md b/roles/dj-wasabi.telegraf/CODE_OF_CONDUCT.md new file mode 100644 index 00000000..e28ac17f --- /dev/null +++ b/roles/dj-wasabi.telegraf/CODE_OF_CONDUCT.md @@ -0,0 +1,3 @@ +# Code of Conduct + +The Code of Conduct from Ansible found [here](https://docs.ansible.com/ansible/devel/community/code_of_conduct.html) applies to this Ansible role as well. diff --git a/roles/dj-wasabi.telegraf/CONTRIBUTING.md b/roles/dj-wasabi.telegraf/CONTRIBUTING.md new file mode 100644 index 00000000..4b8af376 --- /dev/null +++ b/roles/dj-wasabi.telegraf/CONTRIBUTING.md @@ -0,0 +1,88 @@ +# Contributing to this role + +**Table of content** + +- [Contributing to this role](#contributing-to-this-role) + * [Contributing](#contributing) + * [(local) Development](#-local--development) + + [Requirements](#requirements) + + [Execution](#execution) +- [Other](#other) + * [Virtualenv](#virtualenv) + * [Links](#links) + +Thank you very much for making time to improve this Ansible role. + +## Contributing + +Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms. [Contributor Code of Conduct](https://docs.ansible.com/ansible/devel/community/code_of_conduct.html). + +1. Fork the repo + +2. Create a branch and apply your changes to this branch. + + a. Make sure you have updated the documentation when adding new variables; + + b. Don't forget to add/update tests so we can test the functionality during each Pull Request; + + c. Make sure the tests will succeed. + +3. Push the branch to your fork and submit a pull request. + +**Note** + +Pull Requests that fails during the tests will not be merged. + +## Coding Guidelines + +Style guides are important because they ensure consistency in the content, look, and feel of a book or a website. + +* [Ansible Style Guide](http://docs.ansible.com/ansible/latest/dev_guide/style_guide/) +* It's "Ansible" when referring to the product and ``ansible`` when referring to the command line tool, package, etc +* Playbooks should be written in multi-line YAML with ``key: value``. The form ``key=value`` is only for ``ansible`` ad-hoc, not for ``ansible-playbook``. +* Tasks should always have a ``name:`` + +## (local) Development + +This role make use of Molecule to test the execution of the role and verificate it. In the root of the repository, a file named `requirements.txt` exists and contains the versions used by the tests. + +### Requirements + +You can install them with the following command: + +``` +pip install -r requirements.txt +``` + +Once the dependencies are installed, please install Docker as Molecule is configured in this repository to create Docker containers. See [this](https://docs.docker.com/install/) link to install Docker on your system. + +### Execution + +Once everything is installed, you can validate your changes by executing: +``` +molecule test +``` + +It should run without any issues. + +# Other + +## Virtualenv + +Suggestion is to create a virtualenv so you won't have issues with other projects. + +Some web pages describing for virtual env: + +* http://thepythonguru.com/python-virtualenv-guide/ +* https://realpython.com/python-virtual-environments-a-primer/ +* https://www.dabapps.com/blog/introduction-to-pip-and-virtualenv-python/ + +## Links + +[Molecule](https://molecule.readthedocs.io/) + +[Ansible](https://www.ansible.com/) + +[Molecule V2 with your own role](https://werner-dijkerman.nl/2017/09/05/using-molecule-v2-to-test-ansible-roles/) + +**End note**: Have fun making changes. If a feature helps you, then others find it helpful too and I will happily have it merged. diff --git a/roles/dj-wasabi.telegraf/LICENSE b/roles/dj-wasabi.telegraf/LICENSE new file mode 100644 index 00000000..6922fb32 --- /dev/null +++ b/roles/dj-wasabi.telegraf/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2018 Werner Dijkerman + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/roles/dj-wasabi.telegraf/PULL_REQUEST_TEMPLATE.md b/roles/dj-wasabi.telegraf/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 00000000..70c5edef --- /dev/null +++ b/roles/dj-wasabi.telegraf/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,12 @@ +**Description of PR** + + +**Type of change** + + +Feature Pull Request +Bugfix Pull Request +Docs Pull Request + +**Fixes an issue** + diff --git a/roles/dj-wasabi.telegraf/README.md b/roles/dj-wasabi.telegraf/README.md index 64508b28..5b65c891 100644 --- a/roles/dj-wasabi.telegraf/README.md +++ b/roles/dj-wasabi.telegraf/README.md @@ -36,6 +36,8 @@ The following parameters can be set for the Telegraf agent: * `telegraf_agent_round_interval`: Rounds collection interval to 'interval' Default: True * `telegraf_agent_flush_interval`: Default data flushing interval for all outputs. Default: 10 * `telegraf_agent_flush_jitter`: Jitter the flush interval by a random amount. Default: 0 +* `telegraf_agent_aws_tags`: Configure AWS ec2 tags into Telegraf tags section Default: `False` +* `telegraf_agent_aws_tags_prefix`: Define a prefix for AWS ec2 tags. Default: `""` * `telegraf_agent_collection_jitter`: Jitter the collection by a random amount. Default: 0 (since v0.13) * `telegraf_agent_metric_batch_size`: The agent metric batch size. Default: 1000 (since v0.13) * `telegraf_agent_metric_buffer_limit`: The agent metric buffer limit. Default: 10000 (since v0.13) @@ -68,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. -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_extra` @@ -88,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. -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 telegraf_plugins_extra: - - plugin: mysql + mysql: config: - servers = ["root:{{ mysql_root_password }}@tcp(localhost:3306)/"] @@ -129,15 +131,28 @@ No dependencies roles: - { role: dj-wasabi.telegraf } -##Contributors +## Contributors + The following have contributed to this Ansible role: - * aferrari-technisys - * stvnwrgs - * lhoss - * thecodeassassin - * Ismael - * romainbureau + * Thomas Szymanski + * Alejandro + * Slawomir Skowron + * Ismael + * Laurent Hoss + * Anthony ARNAUD + * Rick Box + * Emerson Knapp + * gaelL + * Steven Wirges + * zend0 + * Angristan + * Olivier Boukili + * Romain BUREAU + * TheCodeAssassin + * tjend + +Thank you all! ## Molecule diff --git a/roles/dj-wasabi.telegraf/defaults/main.yml b/roles/dj-wasabi.telegraf/defaults/main.yml index d947b9a6..bd799c9c 100644 --- a/roles/dj-wasabi.telegraf/defaults/main.yml +++ b/roles/dj-wasabi.telegraf/defaults/main.yml @@ -1,13 +1,15 @@ --- # defaults file for ansible-telegraf -telegraf_agent_version: 1.4.0 +telegraf_agent_version: 1.7.3 telegraf_agent_hostname: "{{ ansible_fqdn }}" telegraf_agent_interval: 10 telegraf_agent_debug: False telegraf_agent_round_interval: True telegraf_agent_flush_interval: 10 telegraf_agent_flush_jitter: 0 +telegraf_agent_aws_tags: False +telegraf_agent_aws_tags_prefix: "" # v0.13 settings (not sure if supported in older version): telegraf_agent_collection_jitter: 0 @@ -28,6 +30,7 @@ telegraf_agent_output: - database = "telegraf" - precision = "s" +# defaults - /etc/telegraf/telegraf.conf telegraf_plugins_default: - plugin: cpu config: @@ -39,5 +42,11 @@ telegraf_plugins_default: - plugin: system - plugin: swap - plugin: netstat + - plugin: processes + - plugin: kernel -telegraf_plugins_extra: +# extra configuration - /etc/telegraf/telegraf.d/* +telegraf_plugins_extra: {} + +# RedHat specific settings for convenience +telegraf_redhat_releasever: "$releasever" diff --git a/roles/dj-wasabi.telegraf/meta/.galaxy_install_info b/roles/dj-wasabi.telegraf/meta/.galaxy_install_info index 9757037e..18a7f393 100644 --- a/roles/dj-wasabi.telegraf/meta/.galaxy_install_info +++ b/roles/dj-wasabi.telegraf/meta/.galaxy_install_info @@ -1 +1 @@ -{install_date: 'Mon Apr 23 15:26:37 2018', version: 0.8.0} +{install_date: 'Thu Oct 4 19:30:12 2018', version: 0.10.0} diff --git a/roles/dj-wasabi.telegraf/meta/main.yml b/roles/dj-wasabi.telegraf/meta/main.yml index c8424867..016e57c5 100644 --- a/roles/dj-wasabi.telegraf/meta/main.yml +++ b/roles/dj-wasabi.telegraf/meta/main.yml @@ -4,7 +4,7 @@ galaxy_info: description: Installing and configuring Telegraf company: license: license BSD - min_ansible_version: 1.2 + min_ansible_version: 2.4 platforms: - name: EL versions: diff --git a/roles/dj-wasabi.telegraf/molecule/default/create.yml b/roles/dj-wasabi.telegraf/molecule/default/create.yml index ac0110be..eca41c5a 100644 --- a/roles/dj-wasabi.telegraf/molecule/default/create.yml +++ b/roles/dj-wasabi.telegraf/molecule/default/create.yml @@ -39,7 +39,7 @@ image: "molecule_local/{{ item.image }}" state: started recreate: False - log_driver: syslog + log_driver: none command: "{{ item.command | default('sleep infinity') }}" privileged: "{{ item.privileged | default(omit) }}" volumes: "{{ item.volumes | default(omit) }}" diff --git a/roles/dj-wasabi.telegraf/molecule/default/molecule.yml b/roles/dj-wasabi.telegraf/molecule/default/molecule.yml index f09ba133..1ae3e205 100644 --- a/roles/dj-wasabi.telegraf/molecule/default/molecule.yml +++ b/roles/dj-wasabi.telegraf/molecule/default/molecule.yml @@ -13,8 +13,13 @@ platforms: image: milcom/centos7-systemd privileged: True - name: telegraf-debian - image: maint/debian-systemd + image: minimum2scp/systemd-stretch privileged: True + command: /sbin/init + - name: telegraf-ubuntu + image: solita/ubuntu-systemd:bionic + privileged: True + command: /sbin/init provisioner: name: ansible diff --git a/roles/dj-wasabi.telegraf/molecule/default/playbook.yml b/roles/dj-wasabi.telegraf/molecule/default/playbook.yml index fad773b8..dd38a776 100644 --- a/roles/dj-wasabi.telegraf/molecule/default/playbook.yml +++ b/roles/dj-wasabi.telegraf/molecule/default/playbook.yml @@ -4,12 +4,19 @@ - name: "Installing which on CentOS" yum: name: which - state: installed - when: ansible_distribution == 'CentOS' + state: present + when: + - ansible_os_family == 'RedHat' + - name: "Installing wget on Debian" apt: - name: wget - state: installed - when: ansible_distribution == 'Debian' + name: "{{ item }}" + state: present + when: + - ansible_os_family == 'Debian' + with_items: + - wget + - gpg + roles: - role: ansible-telegraf diff --git a/roles/dj-wasabi.telegraf/molecule/default/yaml-lint.yml b/roles/dj-wasabi.telegraf/molecule/default/yaml-lint.yml index ab5cdeba..cd377bf6 100644 --- a/roles/dj-wasabi.telegraf/molecule/default/yaml-lint.yml +++ b/roles/dj-wasabi.telegraf/molecule/default/yaml-lint.yml @@ -4,6 +4,6 @@ extends: default rules: line-length: - max: 120 + max: 140 level: warning truthy: disable diff --git a/roles/dj-wasabi.telegraf/requirements.txt b/roles/dj-wasabi.telegraf/requirements.txt new file mode 100644 index 00000000..f3b20214 --- /dev/null +++ b/roles/dj-wasabi.telegraf/requirements.txt @@ -0,0 +1,4 @@ +ansible==2.4.4.0 +docker==3.3.0 +molecule==2.13.1 +testinfra==1.12.0 diff --git a/roles/dj-wasabi.telegraf/tasks/Debian.yml b/roles/dj-wasabi.telegraf/tasks/Debian.yml index c28b9a81..d07077d4 100644 --- a/roles/dj-wasabi.telegraf/tasks/Debian.yml +++ b/roles/dj-wasabi.telegraf/tasks/Debian.yml @@ -4,9 +4,6 @@ stat: path: /usr/lib/apt/methods/https register: apt_https_transport - tags: - - telegraf - - packages - name: Install APT HTTPS transport. apt: @@ -14,18 +11,12 @@ state: present when: not apt_https_transport.stat.exists become: yes - tags: - - telegraf - - packages - name: Download Telegraf apt key. apt_key: url: "https://repos.influxdata.com/influxdb.key" state: present become: yes - tags: - - telegraf - - packages - name: Add Telegraf repository (using LSB). apt_repository: @@ -33,9 +24,6 @@ filename: "telegraf" state: present become: yes - tags: - - telegraf - - packages when: ansible_lsb is defined and ansible_lsb.codename is defined - name: Add Telegraf repository. @@ -44,17 +32,11 @@ filename: "telegraf" state: present become: yes - tags: - - telegraf - - packages when: ansible_lsb is not defined or ansible_lsb.codename is not defined - name: "Install telegraf package | Debian" apt: - name: telegraf - state: installed + name: "telegraf" + state: present notify: "Restart Telegraf" become: yes - tags: - - telegraf - - packages diff --git a/roles/dj-wasabi.telegraf/tasks/RedHat.yml b/roles/dj-wasabi.telegraf/tasks/RedHat.yml index 547d5a90..f43df738 100644 --- a/roles/dj-wasabi.telegraf/tasks/RedHat.yml +++ b/roles/dj-wasabi.telegraf/tasks/RedHat.yml @@ -1,10 +1,11 @@ --- +# description: RedHat specific installation - name: "Add yum repository | RedHat" yum_repository: name: influxdb description: InfluxDB Repository - RHEL $releasever - baseurl: https://repos.influxdata.com/rhel/$releasever/$basearch/stable + baseurl: "https://repos.influxdata.com/rhel/{{ telegraf_redhat_releasever }}/$basearch/stable" gpgcheck: yes gpgkey: https://repos.influxdata.com/influxdb.key diff --git a/roles/dj-wasabi.telegraf/tasks/configure.yml b/roles/dj-wasabi.telegraf/tasks/configure.yml new file mode 100644 index 00000000..103565d4 --- /dev/null +++ b/roles/dj-wasabi.telegraf/tasks/configure.yml @@ -0,0 +1,60 @@ +--- +# description: Configure telegraf and get all relevent ec2 information + +- name: Retrieve ec2 facts + ec2_facts: + when: telegraf_agent_aws_tags + +- name: Retrieve all ec2 tags on the instance + ec2_tag: + region: '{{ ansible_ec2_placement_region }}' + resource: '{{ ansible_ec2_instance_id }}' + state: list + when: telegraf_agent_aws_tags + register: ec2_tags + +- name: "Copy the template for versions < 0.10.0" + template: + src: etc-opt-telegraf-telegraf.conf.j2 + dest: /etc/opt/telegraf/telegraf.conf + owner: telegraf + group: telegraf + mode: 0640 + become: yes + when: telegraf_agent_version is version_compare('0.10.0', '<') + notify: "Restart Telegraf" + +- name: "Copy the template for versions >= 0.10.0" + template: + src: telegraf.conf.j2 + dest: /etc/telegraf/telegraf.conf + owner: telegraf + group: telegraf + mode: 0640 + become: yes + when: telegraf_agent_version is version_compare('0.10.0', '>=') + notify: "Restart Telegraf" + +- name: "Copy telegraf extra plugins" + template: + src: "telegraf-extra-plugin.conf.j2" + dest: "/etc/telegraf/telegraf.d/{{ item.key }}.conf" + owner: telegraf + group: telegraf + mode: 0640 + with_dict: "{{ telegraf_plugins_extra }}" + when: "telegraf_plugins_extra is defined and telegraf_plugins_extra is iterable and item.value.state|default('present') != 'absent'" + become: yes + notify: "Restart Telegraf" + +- name: "Remove telegraf extra plugins" + file: + path: "/etc/telegraf/telegraf.d/{{ item.key }}.conf" + state: absent + with_dict: "{{ telegraf_plugins_extra }}" + when: "telegraf_plugins_extra is defined and telegraf_plugins_extra is iterable and item.value.state|default('present') == 'absent'" + become: yes + notify: "Restart Telegraf" + +- name: "Force restart service after reread config" + meta: flush_handlers diff --git a/roles/dj-wasabi.telegraf/tasks/main.yml b/roles/dj-wasabi.telegraf/tasks/main.yml index eb9efa83..0f850ef9 100644 --- a/roles/dj-wasabi.telegraf/tasks/main.yml +++ b/roles/dj-wasabi.telegraf/tasks/main.yml @@ -2,43 +2,15 @@ # tasks file for ansible-telegraf - name: "Install the correct repository" - include: "RedHat.yml" + include_tasks: "RedHat.yml" when: ansible_os_family == "RedHat" - name: "Install the correct repository" - include: "Debian.yml" + include_tasks: "Debian.yml" when: ansible_os_family == "Debian" + tags: + - telegraf + - packages -- name: "Copy the template for versions < 0.10.0" - template: - src: etc-opt-telegraf-telegraf.conf.j2 - dest: /etc/opt/telegraf/telegraf.conf - owner: telegraf - group: telegraf - mode: 0640 - become: yes - when: telegraf_agent_version|version_compare('0.10.0', '<') - notify: "Restart Telegraf" - -- name: "Copy the template for versions >= 0.10.0" - template: - src: telegraf.conf.j2 - dest: /etc/telegraf/telegraf.conf - owner: telegraf - group: telegraf - mode: 0640 - become: yes - when: telegraf_agent_version|version_compare('0.10.0', '>=') - notify: "Restart Telegraf" - -- name: "Copy telegraf extra plugins" - template: - src: "telegraf-extra-plugin.conf.j2" - dest: "/etc/telegraf/telegraf.d/{{ item.plugin }}.conf" - owner: telegraf - group: telegraf - mode: 0640 - with_items: "{{ telegraf_plugins_extra }}" - when: "telegraf_plugins_extra is defined and telegraf_plugins_extra is iterable" - become: yes - notify: "Restart Telegraf" +- name: "Configure telegraf" + include_tasks: "configure.yml" diff --git a/roles/dj-wasabi.telegraf/templates/etc-opt-telegraf-telegraf.conf.j2 b/roles/dj-wasabi.telegraf/templates/etc-opt-telegraf-telegraf.conf.j2 index 9059fd3a..ba15c6dd 100644 --- a/roles/dj-wasabi.telegraf/templates/etc-opt-telegraf-telegraf.conf.j2 +++ b/roles/dj-wasabi.telegraf/templates/etc-opt-telegraf-telegraf.conf.j2 @@ -1,4 +1,4 @@ -# Telegraf configuration +### MANAGED BY {{ role_path|basename }} ANSIBLE ROLE ### [tags] {% if telegraf_global_tags is defined and telegraf_global_tags is iterable %} @@ -7,6 +7,12 @@ {% endfor %} {% endif %} +{% if telegraf_agent_aws_tags == true and ec2_tags is defined and ec2_tags != None %} +{% for key, value in ec2_tags.tags.iteritems()%} + {{telegraf_agent_aws_tags_prefix}}{{ key }} = "{{ value }}" +{% endfor %} +{% endif %} + # Configuration for telegraf itself [agent] interval = "{{ telegraf_agent_interval }}s" diff --git a/roles/dj-wasabi.telegraf/templates/telegraf-extra-plugin.conf.j2 b/roles/dj-wasabi.telegraf/templates/telegraf-extra-plugin.conf.j2 index ff5d188c..452b722c 100644 --- a/roles/dj-wasabi.telegraf/templates/telegraf-extra-plugin.conf.j2 +++ b/roles/dj-wasabi.telegraf/templates/telegraf-extra-plugin.conf.j2 @@ -1,45 +1,47 @@ -[[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 %} +### MANAGED BY {{ role_path|basename }} ANSIBLE ROLE ### + +[[inputs.{{ item.value.plugin | default(item.key) }}]] +{% if item.value.interval is defined %} + interval = "{{ item.value.interval }}s" +{% endif %} +{% if item.value.config is defined and item.value.config is iterable %} +{% for items in item.value.config %} {{ items }} {% endfor %} {% endif %} -{% if item.tags is defined and item.tags is iterable %} -[inputs.{{ item.plugin }}.tags] -{% for items in item.tags %} +{% if item.value.tags is defined and item.value.tags is iterable %} +[inputs.{{ item.value.plugin | default(item.key) }}.tags] +{% for items in item.value.tags %} {{ items }} {% endfor %} {% endif %} -{% if item.tagpass is defined and item.tagpass is iterable %} -[{{ item.plugin }}.tagpass] -{% for items in item.tagpass %} +{% if item.value.tagpass is defined and item.value.tagpass is iterable %} +[{{ item.value.plugin | default(item.key) }}.tagpass] +{% for items in item.value.tagpass %} {{ items }} {% endfor %} {% endif %} -{% if item.tagdrop is defined and item.tagdrop is iterable %} -[{{ item.plugin }}.tagdrop] -{% for items in item.tagdrop %} +{% if item.value.tagdrop is defined and item.value.tagdrop is iterable %} +[{{ item.value.plugin | default(item.key) }}.tagdrop] +{% for items in item.value.tagdrop %} {{ items }} {% endfor %} {% endif %} -{% if item.pass is defined and item.pass is iterable %} -[{{ item.plugin }}.pass] -{% for items in item.pass %} +{% if item.value.pass is defined and item.value.pass is iterable %} +[{{ item.value.plugin | default(item.key) }}.pass] +{% for items in item.value.pass %} {{ items }} {% endfor %} {% endif %} -{% if item.drop is defined and item.drop is iterable %} -[{{ item.plugin }}.drop] -{% for items in item.drop %} +{% if item.value.drop is defined and item.value.drop is iterable %} +[{{ item.value.plugin | default(item.key) }}.drop] +{% for items in item.value.drop %} {{ items }} {% endfor %} {% endif %} -{% if item.specifications is defined and item.specifications is iterable %} -[[{{item.plugin}}.specifications]] -{% for items in item.specifications %} +{% if item.value.specifications is defined and item.value.specifications is iterable %} +[[{{item.value.plugin | default(item.key)}}.specifications]] +{% for items in item.value.specifications %} {{ items }} {% endfor %} {% endif %} diff --git a/roles/dj-wasabi.telegraf/templates/telegraf.conf.j2 b/roles/dj-wasabi.telegraf/templates/telegraf.conf.j2 index 7a96c007..98dd7211 100644 --- a/roles/dj-wasabi.telegraf/templates/telegraf.conf.j2 +++ b/roles/dj-wasabi.telegraf/templates/telegraf.conf.j2 @@ -1,4 +1,4 @@ -# Telegraf configuration +### MANAGED BY {{ role_path|basename }} ANSIBLE ROLE ### [global_tags] {% if telegraf_global_tags is defined and telegraf_global_tags is iterable %} @@ -7,6 +7,12 @@ {% endfor %} {% endif %} +{% if telegraf_agent_aws_tags == true and ec2_tags is defined and ec2_tags != None %} +{% for key, value in ec2_tags.tags.iteritems()%} + {{telegraf_agent_aws_tags_prefix}}{{ key }} = "{{ value }}" +{% endfor %} +{% endif %} + # Configuration for telegraf agent [agent] interval = "{{ telegraf_agent_interval }}s" @@ -15,13 +21,13 @@ round_interval = {{ telegraf_agent_round_interval | lower }} flush_interval = "{{ telegraf_agent_flush_interval }}s" flush_jitter = "{{ telegraf_agent_flush_jitter }}s" -{% if telegraf_agent_version|version_compare('0.13', '>=') %} +{% if telegraf_agent_version is version_compare('0.13', '>=') %} collection_jitter = "{{ telegraf_agent_collection_jitter }}s" metric_batch_size = {{ telegraf_agent_metric_batch_size }} metric_buffer_limit = {{ telegraf_agent_metric_buffer_limit }} quiet = {{ telegraf_agent_quiet | lower }} {% endif %} -{% if telegraf_agent_version|version_compare('1.1', '>=') %} +{% if telegraf_agent_version is version_compare('1.1', '>=') %} logfile = "{{ telegraf_agent_logfile }}" omit_hostname = {{ telegraf_agent_omit_hostname | lower }} {% endif %}