feat: added telegraf configuration deployment using template

Signed-off-by: Louis Vallat <contact@louis-vallat.dev>
This commit is contained in:
Louis Vallat 2025-01-08 11:30:36 +01:00
parent a03e2953aa
commit 83da79bf82
Signed by: louis
SSH Key Fingerprint: SHA256:0iPwDU/PZtEy/K13Oar4TzmcunmI9H5U9IsOR3jyT/Q
4 changed files with 50 additions and 47 deletions

View File

@ -0,0 +1,5 @@
---
- name: Restart telegraf
ansible.builtin.service:
name: telegraf.service
state: restarted

View File

@ -1,49 +1,17 @@
--- ---
- name: Install required system packages
ansible.builtin.apt:
pkg:
- apt-transport-https
- ca-certificates
- gnupg
- curl
state: latest
update_cache: true
- name: Add Influxdata GPG apt key
ansible.builtin.apt_key:
url: "https://repos.influxdata.com/influxdata-archive.key"
state: present
- name: Add Influxdata repository
ansible.builtin.apt_repository:
repo: deb https://repos.influxdata.com/{{ ansible_distribution | lower }} {{ ansible_distribution_release }} stable
state: present
filename: "telegraf"
- name: Install telegraf package
ansible.builtin.apt:
pkg:
- telegraf
state: latest
update_cache: true
- name: Gather the package facts
ansible.builtin.package_facts:
manager: auto
- name: Add telegraf to docker group - name: Add telegraf to docker group
ansible.builtin.user: ansible.builtin.user:
name: telegraf name: telegraf
groups: docker groups: docker
append: true append: true
when: "'docker-ce' in ansible_facts.packages" when: "docker is defined and docker == 'true'"
notify:
- Restart telegraf
- name: Enable telegraf service - name: Deploy configuration file
ansible.builtin.service: ansible.builtin.template:
name: telegraf src: telegraf.conf.j2
enabled: true dest: /etc/telegraf/telegraf.conf
mode: "644"
- name: Stop telegraf service (configure it before starting) notify:
ansible.builtin.service: - Restart telegraf
name: telegraf
state: stopped

View File

@ -1,5 +0,0 @@
---
- name: "Install telegraf on debian."
hosts: telegraf
roles:
- telegraf

View File

@ -0,0 +1,35 @@
[agent]
hostname = "{{ansible_hostname}}"
flush_interval = "15s"
interval = "15s"
[[inputs.cpu]]
percpu = true
totalcpu = true
collect_cpu_time = false
report_active = false
[[inputs.disk]]
ignore_fs = ["tmpfs", "devtmpfs", "devfs"]
[[inputs.diskio]]
[[inputs.mem]]
[[inputs.netstat]]
[[inputs.net]]
ignore_protocol_stats = true
[[inputs.system]]
[[inputs.swap]]
[[inputs.processes]]
[[inputs.kernel]]
{% if docker == true %}
[[inputs.docker]]
endpoint = "unix:///var/run/docker.sock"
container_names = []
timeout = "5s"
total = false
{% endif %}
[[outputs.influxdb_v2]]
urls = ["https://influxdb.louis-vallat.dev"]
organization = "louis-vallat.dev"
bucket = "telegraf"
token = "{{telegraf_token}}"