60 lines
1.7 KiB
YAML
60 lines
1.7 KiB
YAML
---
|
|
- name: Fix Linux Telegraf configs
|
|
hosts: linux_servers
|
|
gather_facts: false
|
|
vars:
|
|
influxdb_url: "http://docker2.tail99133.ts.net:8086"
|
|
influxdb_org: "homelab"
|
|
influxdb_bucket: "telegraf"
|
|
telegraf_conf_path: /etc/telegraf/telegraf.conf
|
|
secret_path: /etc/telegraf/secrets/token
|
|
nas_token_path: /mnt/nas/public/Hermes_Data/secrets/influxdb/token
|
|
|
|
tasks:
|
|
- name: Read InfluxDB token from NAS
|
|
local_action:
|
|
module: slurp
|
|
src: "{{ nas_token_path }}"
|
|
register: nas_token
|
|
run_once: true
|
|
|
|
- name: Set InfluxDB token fact
|
|
set_fact:
|
|
influxdb_token: "{{ nas_token.content | b64decode }}"
|
|
|
|
- name: Deploy InfluxDB token to secret path
|
|
copy:
|
|
content: "{{ influxdb_token }}"
|
|
dest: "{{ secret_path }}"
|
|
mode: "0600"
|
|
owner: root
|
|
group: root
|
|
|
|
- name: Update telegraf.conf URL
|
|
replace:
|
|
path: "{{ telegraf_conf_path }}"
|
|
regexp: 'urls = \[.*\]'
|
|
replace: 'urls = ["{{ influxdb_url }}"]'
|
|
|
|
- name: Update telegraf.conf token reference
|
|
replace:
|
|
path: "{{ telegraf_conf_path }}"
|
|
regexp: 'token = ".*"'
|
|
replace: 'token = "@{{ secret_path }}"'
|
|
|
|
- name: Update telegraf.conf org and bucket
|
|
replace:
|
|
path: "{{ telegraf_conf_path }}"
|
|
regexp: "{{ item.regexp }}"
|
|
replace: "{{ item.replace }}"
|
|
loop:
|
|
- regexp: "organization = \".*\""
|
|
replace: "organization = \"{{ influxdb_org }}\""
|
|
- regexp: "bucket = \".*\""
|
|
replace: "bucket = \"{{ influxdb_bucket }}\""
|
|
|
|
- name: Restart Telegraf to apply changes
|
|
service:
|
|
name: telegraf
|
|
state: restarted
|