Files
ansible-pull/roles/server/tasks/utilities/telegraf.yml
2025-11-27 15:22:38 +01:00

159 lines
5.3 KiB
YAML

# - name: server | telegraf | remove repo
# file:
# path: "/etc/apt/sources.list.d/influxdata.list"
# state: absent
# curl --silent --location -O https://repos.influxdata.com/influxdata-archive.key
# gpg --show-keys --with-fingerprint --with-colons ./influxdata-archive.key 2>&1 \
# | grep -q '^fpr:\+24C975CBA61A024EE1B631787C3D57159FC2F927:$' \
# && cat influxdata-archive.key \
# | gpg --dearmor \
# | sudo tee /etc/apt/keyrings/influxdata-archive.gpg > /dev/null \
# && echo 'deb [signed-by=/etc/apt/keyrings/influxdata-archive.gpg] https://repos.influxdata.com/debian stable main' \
# | sudo tee /etc/apt/sources.list.d/influxdata.list
# sudo apt-get update && sudo apt-get install telegraf
- name: server | telegraf | download key
ansible.builtin.uri:
url: "https://repos.influxdata.com/influxdata-archive.key"
dest: "/tmp/influxdate.key"
creates: "/tmp/influxdata.key"
- name: server | telegraf | verify and import key
ansible.builtin.shell:
cmd: "gpg --show-keys --with-fingerprint --with-colons /tmp/influxdata.key 2>&1 | grep -q '^fpr:\\+9D539D90D3328DC7D6C8D3B9D8FF8E1F7DF8B07E:$' && cat /tmp/influxdata.key | gpg --dearmor | tee /etc/apt/keyrings/influxdata.gpg > /dev/null"
creates: "/etc/apt/trusted.gpg.d/influxdata.gpg"
- name: server | telegraf | add repository
ansible.builtin.shell:
cmd: "echo 'deb [signed-by=/etc/apt/trusted.gpg.d/influxdata.gpg] https://repos.influxdata.com/debian stable main' | tee /etc/apt/sources.list.d/influxdata.list"
creates: "/etc/apt/sources.list.d/influxdata.list"
- name: server | telegraf | install telegraf
ansible.builtin.apt:
name: "telegraf"
state: latest
update_cache: yes
- name: server | telegraf | copy basic config
ansible.builtin.copy:
dest: "/etc/telegraf/telegraf.d/{{ item | basename }}"
src: "{{ item }}"
with_fileglob:
- "telegraf.d/*.conf"
notify: restart_telegraf
- name: Configure telegraf agent hostname
tags: telegraf
ansible.builtin.lineinfile:
path: /etc/telegraf/telegraf.conf
regexp: '^\s*#?\s*hostname\s*='
line: ' hostname = "{{ ansible_fqdn }}"'
owner: root
group: root
mode: '0644'
notify: restart_telegraf
when: ansible_distribution in ["Debian", "Ubuntu", "Linux Mint"]
- name: Configure telegraf agent interval
tags: telegraf
ansible.builtin.lineinfile:
path: /etc/telegraf/telegraf.conf
regexp: '^\s*#?\s*interval\s*='
line: ' interval = "{{ telegraf_agent_interval }}"'
owner: root
group: root
mode: '0644'
notify: restart_telegraf
when: ansible_distribution in ["Debian", "Ubuntu", "Linux Mint"]
- name: Configure telegraf agent flush_interval
tags: telegraf
ansible.builtin.lineinfile:
path: /etc/telegraf/telegraf.conf
regexp: '^\s*#?\s*flush_interval\s*='
line: ' flush_interval = "{{ telegraf_agent_flush_interval }}"'
owner: root
group: root
mode: '0644'
notify: restart_telegraf
when: ansible_distribution in ["Debian", "Ubuntu", "Linux Mint"]
- name: Configure telegraf agent flush_jitter
tags: telegraf
ansible.builtin.lineinfile:
path: /etc/telegraf/telegraf.conf
regexp: '^\s*#?\s*flush_jitter\s*='
line: ' flush_jitter = "{{ telegraf_agent_flush_jitter }}"'
owner: root
group: root
mode: '0644'
notify: restart_telegraf
when: ansible_distribution in ["Debian", "Ubuntu", "Linux Mint"]
- name: Configure telegraf agent collection_jitter
tags: telegraf
ansible.builtin.lineinfile:
path: /etc/telegraf/telegraf.conf
regexp: '^\s*#?\s*collection_jitter\s*='
line: ' collection_jitter = "{{ telegraf_agent_collection_jitter }}"'
owner: root
group: root
mode: '0644'
notify: restart_telegraf
when: ansible_distribution in ["Debian", "Ubuntu", "Linux Mint"]
- name: Configure telegraf agent metric_batch_size
tags: telegraf
ansible.builtin.lineinfile:
path: /etc/telegraf/telegraf.conf
regexp: '^\s*#?\s*metric_batch_size\s*='
line: ' metric_batch_size = "{{ telegraf_agent_metric_batch_size }}"'
owner: root
group: root
mode: '0644'
notify: restart_telegraf
when: ansible_distribution in ["Debian", "Ubuntu", "Linux Mint"]
- name: Configure telegraf agent metric_buffer_limit
tags: telegraf
ansible.builtin.lineinfile:
path: /etc/telegraf/telegraf.conf
regexp: '^\s*#?\s*metric_buffer_limit\s*='
line: ' metric_buffer_limit = "{{ telegraf_agent_metric_buffer_limit }}"'
owner: root
group: root
mode: '0644'
notify: restart_telegraf
when: ansible_distribution in ["Debian", "Ubuntu", "Linux Mint"]
- name: Configure telegraf agent round_interval
tags: telegraf
ansible.builtin.lineinfile:
path: /etc/telegraf/telegraf.conf
regexp: '^\s*#?\s*round_interval\s*='
line: ' round_interval = "{{ telegraf_agent_round_interval }}"'
owner: root
group: root
mode: '0644'
notify: restart_telegraf
when: ansible_distribution in ["Debian", "Ubuntu", "Linux Mint"]
- name: server | telegraf | create systemd override directory for telegraf
ansible.builtin.file:
path: /etc/systemd/system/telegraf.service.d
state: directory
mode: '0755'
- name: server | telegraf | define systemd-limits
ansible.builtin.template:
src: telegraf-override.j2
dest: /etc/systemd/system/telegraf.service.d/override.conf
notify:
- reload_systemd
- restart_telegraf