diff --git a/README.md b/README.md index 1326eb4..0ccd4a2 100644 --- a/README.md +++ b/README.md @@ -24,13 +24,13 @@ There was an issue: If I configure a telegraf_plugins_extra, run ansible, delete the plugin and run ansible again, the plugin stays on the machine. - - ## Role Variables The following parameters can be set for the Telegraf agent: -* `telegraf_agent_version`: The version of Telegraf to install. Default: `1.0.0` +* `telegraf_agent_version`: The version of Telegraf to install. Default: `1.9.0` +* `telegraf_agent_package`: The name of the Telegraf package. Default: `telegraf` +* `telegraf_agent_package_state`: If the package should be `present` or `latest`. When set to `latest`, `telegraf_agent_version` will be ignored. Default: `present` * `telegraf_agent_interval`: The interval configured for sending data to the server. Default: `10` * `telegraf_agent_debug`: Run Telegraf in debug mode. Default: `False` * `telegraf_agent_round_interval`: Rounds collection interval to 'interval' Default: True diff --git a/defaults/main.yml b/defaults/main.yml index 069130a..8db0876 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -2,6 +2,9 @@ # defaults file for ansible-telegraf telegraf_agent_version: 1.9.0 +telegraf_agent_version_patch: 1 +telegraf_agent_package: telegraf +telegraf_agent_package_state: latest telegraf_agent_hostname: "{{ ansible_fqdn }}" telegraf_agent_interval: 10 telegraf_agent_debug: False diff --git a/tasks/Debian.yml b/tasks/Debian.yml index f4bcef8..4767efe 100644 --- a/tasks/Debian.yml +++ b/tasks/Debian.yml @@ -1,5 +1,11 @@ --- +- name: "Set name if state == latest" + set_fact: + telegraf_agent_package: telegraf={{ telegraf_agent_version }}-{{ telegraf_agent_version_patch }} + when: + - telegraf_agent_package_state != "latest" + - name: Ensure the system can use the HTTPS transport for APT. stat: path: /usr/lib/apt/methods/https @@ -41,7 +47,8 @@ - name: "Install telegraf package | Debian" apt: - name: "telegraf" - state: present + name: "{{ telegraf_agent_package }}" + state: "{{ telegraf_agent_package_state }}" + force: True notify: "Restart Telegraf" become: yes diff --git a/tasks/RedHat.yml b/tasks/RedHat.yml index f43df73..3197c56 100644 --- a/tasks/RedHat.yml +++ b/tasks/RedHat.yml @@ -1,6 +1,12 @@ --- # description: RedHat specific installation +- name: "Set name if state == latest" + set_fact: + telegraf_agent_package: telegraf-{{ telegraf_agent_version }} + when: + - telegraf_agent_package_state != "latest" + - name: "Add yum repository | RedHat" yum_repository: name: influxdb @@ -11,6 +17,6 @@ - name: "Install telegraf package | RedHat" yum: - name: "telegraf-{{ telegraf_agent_version }}" - state: installed + name: "{{ telegraf_agent_package }}" + state: "{{ telegraf_agent_package_state }}" notify: "Restart Telegraf"