feat: added telegraf configuration deployment using template
Signed-off-by: Louis Vallat <contact@louis-vallat.dev>
This commit is contained in:
parent
a03e2953aa
commit
83da79bf82
5
roles/telegraf/handlers/main.yaml
Normal file
5
roles/telegraf/handlers/main.yaml
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
- name: Restart telegraf
|
||||
ansible.builtin.service:
|
||||
name: telegraf.service
|
||||
state: restarted
|
@ -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
|
||||
ansible.builtin.user:
|
||||
name: telegraf
|
||||
groups: docker
|
||||
append: true
|
||||
when: "'docker-ce' in ansible_facts.packages"
|
||||
when: "docker is defined and docker == 'true'"
|
||||
notify:
|
||||
- Restart telegraf
|
||||
|
||||
- name: Enable telegraf service
|
||||
ansible.builtin.service:
|
||||
name: telegraf
|
||||
enabled: true
|
||||
|
||||
- name: Stop telegraf service (configure it before starting)
|
||||
ansible.builtin.service:
|
||||
name: telegraf
|
||||
state: stopped
|
||||
- name: Deploy configuration file
|
||||
ansible.builtin.template:
|
||||
src: telegraf.conf.j2
|
||||
dest: /etc/telegraf/telegraf.conf
|
||||
mode: "644"
|
||||
notify:
|
||||
- Restart telegraf
|
||||
|
@ -1,5 +0,0 @@
|
||||
---
|
||||
- name: "Install telegraf on debian."
|
||||
hosts: telegraf
|
||||
roles:
|
||||
- telegraf
|
35
templates/telegraf.conf.j2
Normal file
35
templates/telegraf.conf.j2
Normal 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}}"
|
Loading…
x
Reference in New Issue
Block a user