homelab/roles/prometheus/tasks/main.yml

72 lines
2.3 KiB
YAML
Raw Normal View History

2020-04-01 01:47:26 +00:00
- name: Install Prometheus node exporter
2023-05-04 03:27:03 +00:00
ansible.builtin.apt:
2020-04-01 01:47:26 +00:00
name: prometheus-node-exporter
state: present
- name: Run Prometheus node exporter
2023-05-04 03:27:03 +00:00
ansible.builtin.service:
2020-04-01 01:47:26 +00:00
name: prometheus-node-exporter
state: started
2020-07-30 05:10:27 +00:00
- name: Create Prometheus data directory
2023-05-04 03:27:03 +00:00
ansible.builtin.file:
2020-07-30 05:10:27 +00:00
path: "{{ prom_root }}/prometheus"
state: directory
owner: nobody
- name: Create Prometheus config directory
2023-05-04 03:27:03 +00:00
ansible.builtin.file:
2020-07-30 05:10:27 +00:00
path: "{{ prom_root }}/config"
2020-04-01 01:47:26 +00:00
state: directory
2020-03-21 06:38:35 +00:00
- name: Install Prometheus configuration
2023-05-04 03:27:03 +00:00
ansible.builtin.template:
src: prometheus.yml.j2
2020-07-30 05:10:27 +00:00
dest: "{{ prom_root }}/config/prometheus.yml"
2020-03-21 06:38:35 +00:00
- name: Create Prometheus network
2023-05-04 03:27:03 +00:00
community.general.docker_network:
name: "{{ prom_name }}"
2020-03-21 00:32:44 +00:00
- name: Start Prometheus container
2023-05-04 03:27:03 +00:00
community.general.docker_container:
2020-03-21 00:32:44 +00:00
name: "{{ prom_name }}"
image: prom/prometheus:{{ prom_version }}
2020-03-21 05:35:51 +00:00
state: started
2020-03-21 00:32:44 +00:00
restart_policy: always
2020-07-30 05:10:27 +00:00
volumes:
- "{{ prom_root }}/config:/etc/prometheus"
- "{{ prom_root }}/prometheus:/prometheus"
networks_cli_compatible: true
networks:
- name: "{{ prom_name }}"
- name: traefik
labels:
traefik.http.routers.prometheus.rule: "Host(`{{ prom_domain }}`)"
traefik.http.routers.prometheus.entrypoints: websecure
traefik.http.routers.prometheus.middlewares: "securehttps@file,localonly"
traefik.http.routers.prometheus.tls.certresolver: letsencrypt
traefik.http.middlewares.localonly.ipwhitelist.sourcerange: "{{ traefik_localonly }}"
traefik.docker.network: traefik
traefik.enable: "true"
2020-04-01 01:47:26 +00:00
- name: Start Grafana container
2023-05-04 03:27:03 +00:00
community.general.docker_container:
name: "{{ grafana_name }}"
image: grafana/grafana:{{ grafana_version }}
2020-07-29 04:43:31 +00:00
state: started
restart_policy: always
2020-08-10 02:06:41 +00:00
user: root
2020-08-01 03:05:11 +00:00
volumes: "{{ grafana_root }}:/var/lib/grafana"
networks_cli_compatible: true
networks:
- name: "{{ prom_name }}"
- name: traefik
labels:
traefik.http.routers.grafana.rule: "Host(`{{ grafana_domain }}`)"
traefik.http.routers.grafana.entrypoints: websecure
traefik.http.routers.grafana.tls.certresolver: letsencrypt
traefik.http.routers.grafana.middlewares: "securehttps@file"
traefik.docker.network: traefik
traefik.enable: "true"