Add monitoring host with prometheus role

This commit is contained in:
2026-01-15 22:59:18 -07:00
parent 05a4aa111f
commit f7c1caa678
11 changed files with 122 additions and 0 deletions

View File

View File

@@ -0,0 +1,4 @@
- name: Restart prometheus
service:
name: prometheus
state: restarted

View File

@@ -0,0 +1,73 @@
- name: Download and verify the prometheus archive
get_url:
url: https://github.com/prometheus/prometheus/releases/download/v{{ prometheus_version }}/prometheus-{{ prometheus_version }}.linux-amd64.tar.gz
dest: /tmp/prometheus-{{ prometheus_version }}.linux-amd64.tar.gz
checksum: "sha256:{{ prometheus_sha256 }}"
register: download_result
- name: Unarchive prometheus binary
unarchive:
src: {{ download_result.dest }}
dest: /usr/local/bin/prometheus
remote_src: true # Indicates the source file is on the remote host
owner: root
group: root
mode: 0755
- name: Create a prometheus group
group:
name: prometheus
state: present
gid: 1051
- name: Create a prometheus user
user:
name: prometheus
uid: 1051
group: 1051
comment: "prometheus user"
shell: /bin/bash
state: present
create_home: no
- name: Create prometheus data and config directories
file:
path: "{{ item }}"
state: directory
mode: 0750
owner: prometheus
group: prometheus
loop:
- /var/lib/prometheus
- /etc/prometheus
- name: Install prometheus config
template:
src: templates/prometheus.yml.j2
dest: /etc/prometheus/prometheus.yml
owner: prometheus
group: prometheus
mode: '0640'
notify: Restart prometheus
- name: Install prometheus service
template:
src: templates/prometheus.service.j2
dest: /etc/systemd/system/prometheus.service
owner: root
group: root
mode: 0640
register: prometheus_service
notify: Restart prometheus
- name: systemctl daemon-reload to pickup prometheus service changes
systemd_service:
daemon_reload: true
when: prometheus_service.changed
notify: Restart prometheus
- name: Start and enable prometheus
service:
name: prometheus
state: started
enabled: true

View File

@@ -0,0 +1,15 @@
[Unit]
Description=Prometheus Server
Documentation=https://prometheus.io
Wants=network-online.target
After=network-online.target
[Service]
User=prometheus
Group=prometheus
Type=simple
ExecStart=/usr/local/bin/prometheus --config.file=/etc/prometheus/prometheus.yml --storage.tsdb.path=/var/lib/prometheus/
[Install]
WantedBy=multi-user.target

View File

@@ -0,0 +1,18 @@
global:
scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
alerting:
alertmanagers:
- static_configs:
- targets:
# - alertmanager:9093
rule_files:
# - "first_rules.yml"
# - "second_rules.yml"
scrape_configs:
- job_name: "prometheus"
static_configs:
- targets: ["localhost:9090"]