146 lines
3.2 KiB
YAML
146 lines
3.2 KiB
YAML
---
|
|
|
|
- name: group for telegraf user
|
|
group:
|
|
state: present
|
|
name: "{{ systemuserlist.telegraf.username }}"
|
|
gid: "{{ systemuserlist.telegraf.gid }}"
|
|
tags: users
|
|
notify: restart telegraf
|
|
|
|
- name: telegraf user
|
|
user:
|
|
state: present
|
|
name: "{{ systemuserlist.telegraf.username }}"
|
|
group: "{{ systemuserlist.telegraf.username }}"
|
|
shell: "{{ systemuserlist.telegraf.shell }}"
|
|
uid: "{{ systemuserlist.telegraf.uid }}"
|
|
create_home: yes
|
|
home: "{{ systemuserlist.telegraf.home }}"
|
|
move_home: yes
|
|
system: yes
|
|
tags: users
|
|
notify: restart telegraf
|
|
|
|
- name: allow telegraf to sudo and use smartctl
|
|
template:
|
|
src: telegraf.sudoers.j2
|
|
dest: /etc/sudoers.d/telegraf
|
|
mode: 0440
|
|
owner: root
|
|
group: root
|
|
when: telegraf_smart_disks
|
|
notify: restart telegraf
|
|
tags: users
|
|
|
|
- name: install humanize
|
|
pip:
|
|
name: humanize
|
|
state: latest
|
|
executable: pip3
|
|
tags:
|
|
- pip
|
|
- packages
|
|
|
|
- name: template vnstat script
|
|
template:
|
|
src: telegraf-vnstat.py.j2
|
|
dest: /usr/local/bin/telegraf-vnstat.py
|
|
mode: 0775
|
|
owner: telegraf
|
|
group: telegraf
|
|
notify: restart telegraf
|
|
|
|
# - name: get list of existing groups
|
|
# shell: "/usr/bin/getent group | awk -F':' '{print $1}'"
|
|
# register: etc_groups
|
|
# check_mode: no
|
|
# changed_when: false
|
|
# tags: users
|
|
#
|
|
# use with:
|
|
#
|
|
# with_items: "{{ systemuserlist.telegraf.groups }}"
|
|
# when: 'item in etc_groups.stdout_lines'
|
|
|
|
- name: add apt key for influxdata to install telegraf
|
|
apt_key:
|
|
url: https://repos.influxdata.com/influxdb.key
|
|
state: present
|
|
tags:
|
|
- packages
|
|
|
|
- name: set distro to debian if raspbian
|
|
set_fact:
|
|
distro: debian
|
|
when: ansible_lsb.id == "Raspbian"
|
|
|
|
- name: otherwise use lsb id
|
|
set_fact:
|
|
distro: "{{ ansible_lsb.id }}"
|
|
when: ansible_lsb.id != "Raspbian"
|
|
|
|
- name: set codename to bullseye if bookworm
|
|
set_fact:
|
|
codename: bullseye
|
|
when: ansible_lsb.codename == "bookworm"
|
|
|
|
- name: set codename to focal if hirsute
|
|
set_fact:
|
|
codename: focal
|
|
when: ansible_lsb.codename == "hirsute"
|
|
|
|
- name: otherwise use lsb codename
|
|
set_fact:
|
|
codename: "{{ ansible_lsb.codename }}"
|
|
when:
|
|
- ansible_lsb.codename != "bookworm"
|
|
- ansible_lsb.codename != "hirsute"
|
|
|
|
- name: add repo for influxdata to install telegraf
|
|
apt_repository:
|
|
repo: deb https://repos.influxdata.com/{{ distro | lower }} {{ codename }} stable
|
|
state: present
|
|
when: not skip_apt|default(false)
|
|
tags:
|
|
- packages
|
|
|
|
- name: install telegraf
|
|
apt:
|
|
name: telegraf
|
|
state: latest
|
|
update_cache: true
|
|
when: not skip_apt|default(false)
|
|
tags:
|
|
- packages
|
|
notify: restart telegraf
|
|
|
|
# telegraf errors and doesnt do the smart check if this
|
|
# isnt installed, regardless of if there are nvme disks
|
|
- name: install nvme-cli for telegraf s.m.a.r.t. monitoring
|
|
apt:
|
|
name: nvme-cli
|
|
state: latest
|
|
when: telegraf_smart_disks
|
|
tags:
|
|
- packages
|
|
notify: restart telegraf
|
|
|
|
- name: template telegraf config
|
|
template:
|
|
src: telegraf.conf.j2
|
|
dest: /etc/telegraf/telegraf.conf
|
|
notify:
|
|
- restart telegraf
|
|
tags:
|
|
- telegraf-config
|
|
|
|
- name: enable telegraf
|
|
service:
|
|
name: telegraf
|
|
state: started
|
|
enabled: yes
|
|
notify: restart telegraf
|
|
|
|
- meta: flush_handlers
|