2019-05-05 14:07:04 +02:00
|
|
|
---
|
|
|
|
- name: Install Prometheus
|
|
|
|
apt:
|
|
|
|
update_cache: true
|
2019-07-22 20:56:43 +02:00
|
|
|
name:
|
|
|
|
- prometheus
|
|
|
|
- prometheus-snmp-exporter
|
2019-05-05 14:07:04 +02:00
|
|
|
register: apt_result
|
|
|
|
retries: 3
|
|
|
|
until: apt_result is succeeded
|
|
|
|
|
|
|
|
- name: Configure Prometheus
|
|
|
|
template:
|
2021-04-01 18:24:21 +02:00
|
|
|
src: "{{ item }}.j2"
|
|
|
|
dest: "/etc/prometheus/{{ item }}"
|
2021-04-01 09:40:22 +02:00
|
|
|
owner: prometheus
|
|
|
|
group: prometheus
|
|
|
|
mode: u=r,g=r,o=
|
2019-07-22 20:56:43 +02:00
|
|
|
loop:
|
2021-04-01 09:40:22 +02:00
|
|
|
- prometheus.yml
|
2021-04-11 15:58:35 +02:00
|
|
|
notify: Restart Prometheus
|
|
|
|
|
2021-04-11 22:01:21 +02:00
|
|
|
- name: Creates directory for alerts
|
2021-04-11 15:58:35 +02:00
|
|
|
file:
|
|
|
|
path: /etc/prometheus/alerts
|
|
|
|
state: directory
|
2021-04-14 19:29:12 +02:00
|
|
|
owner: prometheus
|
|
|
|
group: prometheus
|
2021-04-14 19:51:47 +02:00
|
|
|
mode: 0755
|
2021-04-11 15:58:35 +02:00
|
|
|
|
2021-04-11 22:01:21 +02:00
|
|
|
- name: Remove old files
|
2021-04-11 15:58:35 +02:00
|
|
|
file:
|
|
|
|
path: "/etc/prometheus/{{ item }}"
|
|
|
|
state: absent
|
|
|
|
with_items:
|
2021-04-14 19:51:47 +02:00
|
|
|
- alert.rules.yml
|
2021-04-11 15:58:35 +02:00
|
|
|
- django.rules.yml
|
|
|
|
|
2021-04-11 17:18:32 +02:00
|
|
|
|
2021-04-11 15:58:35 +02:00
|
|
|
- name: Configure Prometheus alerts
|
|
|
|
template:
|
|
|
|
src: "{{ item }}.j2"
|
|
|
|
dest: "/etc/prometheus/alerts/{{ item }}"
|
|
|
|
owner: prometheus
|
|
|
|
group: prometheus
|
|
|
|
mode: u=r,g=r,o=
|
|
|
|
loop:
|
|
|
|
- server.rules.yml
|
2021-04-11 16:43:34 +02:00
|
|
|
- docker.rules.yml
|
2019-07-22 20:56:43 +02:00
|
|
|
- django.rules.yml
|
2021-04-11 15:58:35 +02:00
|
|
|
- ups.rules.yml
|
|
|
|
- postgres.rules.yml
|
2021-04-01 09:40:22 +02:00
|
|
|
notify: Restart Prometheus
|
2019-07-22 20:56:43 +02:00
|
|
|
|
|
|
|
- name: Make Prometheus snmp-exporter listen on localhost only
|
|
|
|
lineinfile:
|
|
|
|
path: /etc/default/prometheus-snmp-exporter
|
|
|
|
regexp: '^ARGS='
|
|
|
|
line: "ARGS=\"--web.listen-address=127.0.0.1:9116\""
|
|
|
|
notify: Restart prometheus-snmp-exporter
|
2019-05-05 14:07:04 +02:00
|
|
|
|
2019-11-01 14:16:32 +01:00
|
|
|
# This file store SNMP OIDs
|
|
|
|
- name: Configure Prometheus snmp-exporter
|
|
|
|
template:
|
2021-04-01 09:40:22 +02:00
|
|
|
src: snmp.yml.j2
|
|
|
|
dest: /etc/prometheus/snmp.yml
|
2019-11-01 14:16:32 +01:00
|
|
|
owner: prometheus
|
2021-04-01 09:40:22 +02:00
|
|
|
group: prometheus
|
|
|
|
mode: u=r,g=r,o=
|
2019-11-01 14:16:32 +01:00
|
|
|
notify: Restart prometheus-snmp-exporter
|
|
|
|
|
2019-05-05 14:07:04 +02:00
|
|
|
# We don't need to restart Prometheus when updating nodes
|
|
|
|
- name: Configure Prometheus nodes
|
|
|
|
copy:
|
|
|
|
content: "{{ prometheus_targets | to_nice_json }}"
|
|
|
|
dest: /etc/prometheus/targets.json
|
2020-11-04 19:31:50 +01:00
|
|
|
mode: 0644
|
2019-07-22 20:56:43 +02:00
|
|
|
|
2019-11-01 14:16:32 +01:00
|
|
|
# We don't need to restart Prometheus when updating nodes
|
|
|
|
- name: Configure Prometheus Ubiquity Unifi SNMP devices
|
|
|
|
copy:
|
|
|
|
content: "{{ prometheus_unifi_snmp_targets | to_nice_json }}"
|
|
|
|
dest: /etc/prometheus/targets_unifi_snmp.json
|
2020-11-04 19:31:50 +01:00
|
|
|
mode: 0644
|
2021-01-29 20:12:14 +01:00
|
|
|
when: prometheus_unifi_snmp_targets is defined
|
2019-11-01 14:16:32 +01:00
|
|
|
|
2021-03-06 01:57:08 +01:00
|
|
|
- name: Configure Prometheus Switchs
|
|
|
|
copy:
|
|
|
|
content: "{{ prometheus_switch_snmp_targets | to_nice_json }}"
|
|
|
|
dest: /etc/prometheus/targets_switch_snmp.json
|
|
|
|
mode: 0644
|
|
|
|
when: prometheus_switch_snmp_targets is defined
|
|
|
|
|
2021-01-21 21:26:40 +01:00
|
|
|
- name: Configure Prometheus UPS SNMP devices
|
|
|
|
copy:
|
|
|
|
content: "{{ [{'targets': prometheus_ups_snmp_targets }] | to_nice_json }}\n"
|
|
|
|
dest: /etc/prometheus/targets_ups_snmp.json
|
|
|
|
mode: 0644
|
2021-01-23 19:01:27 +01:00
|
|
|
when: prometheus_ups_snmp_targets is defined
|
2021-01-21 21:26:40 +01:00
|
|
|
|
2021-02-10 19:06:28 +01:00
|
|
|
- name: Configure Prometheus docker monitoring
|
|
|
|
copy:
|
|
|
|
content: "{{ [{'targets': prometheus_docker_targets }] | to_nice_json }}\n"
|
|
|
|
dest: /etc/prometheus/targets_docker.json
|
|
|
|
mode: 0644
|
|
|
|
when: prometheus_docker_targets is defined
|
|
|
|
|
2021-04-10 18:01:55 +02:00
|
|
|
- name: Configure Prometheus postgres monitoring
|
|
|
|
copy:
|
|
|
|
content: "{{ prometheus_postgres_targets | to_nice_json }}\n"
|
|
|
|
dest: /etc/prometheus/targets_postgres.json
|
|
|
|
mode: 0644
|
|
|
|
when: prometheus_postgres_targets is defined
|
|
|
|
|
2019-07-22 20:56:43 +02:00
|
|
|
- name: Activate prometheus service
|
|
|
|
systemd:
|
|
|
|
name: prometheus
|
2019-07-22 21:04:58 +02:00
|
|
|
enabled: true
|
2019-07-22 20:56:43 +02:00
|
|
|
state: started
|
|
|
|
|
2021-03-06 04:32:06 +01:00
|
|
|
- include_role:
|
|
|
|
name: update_motd
|
|
|
|
vars:
|
|
|
|
motd_messages:
|
|
|
|
- key: 05-prometheus
|
|
|
|
message: >-
|
|
|
|
Prometheus est déployé sur cette machine (voir /etc/prometheus)
|
2021-04-12 10:58:59 +02:00
|
|
|
...
|