Files
ansible/roles/munin_client/tasks/main.yml
2024-07-05 11:53:34 +02:00

131 lines
3.2 KiB
YAML

---
- name: Set package fact
ansible.builtin.set_fact:
muninpkgs:
- muninlite
munin_need_reconfigure: false
when: ansible_facts['distribution'] == "LEDE" or ansible_facts['distribution'] == "OpenWRT" or ansible_facts['distribution'] == "OpenWrt"
- name: Set other packages fact
ansible.builtin.set_fact:
muninpkgs:
- munin-node
- munin-plugins-core
- munin-plugins-extra
munin_need_reconfigure: true
when: ansible_facts['distribution'] == "Debian"
- name: Install munin node packages
ansible.builtin.package:
name: "{{ item }}"
state: present
loop: "{{ muninpkgs }}"
- name: Munin-node conf file
ansible.builtin.template:
src: munin-node.conf.j2
dest: /etc/munin/munin-node.conf
mode: 0644
notify:
- Restart munin-node
when: munin_need_reconfigure
## Adding modules for specific functions
# for NginX webservers
- name: Install LWP::UserAgent
ansible.builtin.package:
name: libwww-perl
state: present
notify:
- Restart munin-node
when: "'webservers' in group_names or 'loadbalancers' in group_names"
# for HAProxy servers
- name: Add HAProxy backend module
ansible.builtin.file:
src: /usr/share/munin/plugins/haproxy_
dest: /etc/munin/plugins/haproxy_current
state: link
notify:
- Restart munin-node
when: "'loadbalancers' in group_names"
# For MariaDB servers
- name: Install Cache::Cache
ansible.builtin.package:
name: libcache-cache-perl
state: present
notify:
- Restart munin-node
when: "'mariadbservers' in group_names"
# For PGSQL servers
- name: Install DBD::Pg
ansible.builtin.package:
name: libdbd-pg-perl
state: present
notify:
- Restart munin-node
when: "'pgsqlservers' in group_names"
# For Munin servers
- name: Execute specific tasks for munin servers
ansible.builtin.include_tasks: mikrotik.yml
when: "'muninservers' in group_names"
# for NUT (UPS) servers
- name: Add specific nut value for UPS
ansible.builtin.file:
path: "/etc/munin/plugins/nutups_eaton3s_{{ item }}"
src: /usr/share/munin/plugins/nutups_
state: link
notify:
- Restart munin-node
when: "'nut_server' in group_names"
loop:
- charge
- voltages
# for physical servers
- name: Execute specific tasks for physical servers
ansible.builtin.include_tasks: physical_servers.yml
when: "'hypervisors' in group_names"
- name: Reconfigure munin-node
ansible.builtin.shell:
cmd: munin-node-configure --shell | sh # noqa: risky-shell-pipe
changed_when: true
notify:
- Restart munin-node
when: munin_need_reconfigure
## Useless junks for everyone
- name: Delete useless junks for everyone
ansible.builtin.file:
path: "/etc/munin/plugins/{{ item }}"
state: absent
when: munin_need_reconfigure
loop:
- users
## Useless junks for LXC
- name: "Delete junks from LXC machines"
ansible.builtin.file:
path: "/etc/munin/plugins/{{ item }}"
state: absent
notify:
- Restart munin-node
when: ansible_facts['virtualization_type'] == "lxc"
loop:
- acpi
- cpuspeed
- diskstats
- entropy
- irqstats
## Useless junks for hypervisors
- name: Execute delete states for hypervisors
ansible.builtin.include_tasks: hypervisors.yml
when: "'hypervisors' in group_names"