- name: Install and configure Telegraf on Debian/Ubuntu hosts: linux_servers gather_facts: true vars: influxdb_url: "http://docker2.tail99133.ts.net:8086" influxdb_org: "homelab" influxdb_bucket: "telegraf" telegraf_conf_path: /etc/telegraf/telegraf.conf secret_search_paths: - "/etc/telegraf/secrets" - "/mnt/nas/public/Hermes_Data/secrets/influxdb" tasks: - name: Ensure InfluxDB repo key is installed apt_key: url: https://repos.influxdata.com/influxdata-archive.key state: present - name: Ensure InfluxDB repo is configured apt_repository: repo: "deb [signed-by=/etc/apt/keyrings/influxdata-archive.gpg] https://repos.influxdata.com/debian stable main" state: present filename: influxdata - name: Install Telegraf apt: name: telegraf state: present update_cache: yes - name: Load InfluxDB token from secret paths slurp: src: "{{ item }}/token" register: token_results failed_when: false loop: "{{ secret_search_paths }}" - name: Set InfluxDB token fact set_fact: influxdb_token: "{{ (token_results.results | selectattr('content') | first).content | b64decode | trim }}" when: token_results.results | selectattr('content') | list | length > 0 - name: Fail if token not found assert: that: - influxdb_token is defined - influxdb_token | length > 0 fail_msg: "InfluxDB token not found in any secret path" - name: Deploy telegraf.conf template: src: templates/telegraf-debian.conf.j2 dest: "{{ telegraf_conf_path }}" owner: telegraf group: telegraf mode: '0640' notify: Restart Telegraf - name: Ensure Telegraf service is enabled and running service: name: telegraf state: started enabled: yes handlers: - name: Restart Telegraf service: name: telegraf state: restarted