Initial Lab Setup
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
- name: Restart Prometheus
|
||||
ansible.builtin.systemd:
|
||||
name: prometheus
|
||||
state: restarted
|
||||
@@ -0,0 +1,85 @@
|
||||
---
|
||||
# 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
|
||||
@@ -0,0 +1,14 @@
|
||||
global:
|
||||
scrape_interval: 15s
|
||||
|
||||
scrape_configs:
|
||||
- job_name: 'prometheus'
|
||||
static_configs:
|
||||
- targets: ['localhost:9090']
|
||||
|
||||
- job_name: 'lab_nodes'
|
||||
static_configs:
|
||||
- targets:
|
||||
{% for host in groups['all_nodes'] %}
|
||||
- '{{ hostvars[host].ansible_host }}:9100'
|
||||
{% endfor %}
|
||||
Reference in New Issue
Block a user