Files
lab-rack/roles/monitoring/tasks/main.yml
T

86 lines
2.3 KiB
YAML
Raw Normal View History

2026-07-06 16:45:51 +02:00
---
# 1. This part runs on EVERY node
- name: Install Node Exporter (Agent)
ansible.builtin.apt:
name: prometheus-node-exporter
state: present
- name: Ensure Node Exporter is running
ansible.builtin.systemd:
name: prometheus-node-exporter
state: started
enabled: yes
# 2. This part ONLY runs on the monitor node
- name: Install Monitoring Server Stack
when: inventory_hostname == 'monitor'
block:
- name: Add Grafana GPG key
ansible.builtin.get_url:
url: https://apt.grafana.com/gpg.key
dest: /usr/share/keyrings/grafana.gpg
mode: '0644'
- name: Add Grafana Repo
ansible.builtin.apt_repository:
repo: "deb [signed-by=/usr/share/keyrings/grafana.gpg] https://apt.grafana.com stable main"
state: present
- name: Ensure prometheus system user exists
ansible.builtin.user:
name: prometheus
shell: /bin/false
system: yes
create_home: no
when: inventory_hostname == 'monitor'
- name: Ensure prometheus data directory has correct permissions
ansible.builtin.file:
path: /var/lib/prometheus
state: directory
owner: prometheus
group: prometheus
mode: '0755'
when: inventory_hostname == 'monitor'
- name: Install Server Packages
ansible.builtin.apt:
name:
- influxdb
- grafana
- prometheus # The server engine
state: present
update_cache: yes
- name: Deploy Prometheus configuration from template
ansible.builtin.template:
src: prometheus.yml.j2
dest: /etc/prometheus/prometheus.yml
owner: prometheus
group: prometheus
mode: '0644'
notify: Restart Prometheus
- name: Ensure Server Services are running
ansible.builtin.systemd:
name: "{{ item }}"
state: started
enabled: yes
loop:
- influxdb
- grafana-server
- prometheus
- name: Configure InfluxDB UDP listener for Proxmox
ansible.builtin.blockinfile:
path: /etc/influxdb/influxdb.conf
insertafter: '\[\[udp\]\]'
block: |
enabled = true
bind-address = ":8089"
database = "proxmox"
batch-size = 1000
batch-timeout = "1s"
when: inventory_hostname == 'monitor'
notify: Restart Influxdb