mirror of
https://github.com/davestephens/ansible-nas
synced 2025-01-13 03:58:47 +00:00
64 lines
2.8 KiB
YAML
64 lines
2.8 KiB
YAML
---
|
|
- name: Start Prometheus
|
|
block:
|
|
- name: Create Prometheus Config Directory
|
|
ansible.builtin.file:
|
|
path: "{{ item }}"
|
|
state: directory
|
|
with_items:
|
|
- "{{ stats_prometheus_data_directory }}"
|
|
- "{{ stats_prometheus_config_directory }}"
|
|
|
|
- name: Create Prometheus Data Directory
|
|
ansible.builtin.file:
|
|
path: "{{ item }}"
|
|
state: directory
|
|
mode: 0777
|
|
with_items:
|
|
- "{{ stats_prometheus_data_directory }}"
|
|
- "{{ stats_prometheus_config_directory }}"
|
|
|
|
- name: Template Prometheus config
|
|
ansible.builtin.template:
|
|
src: prometheus.yml.j2
|
|
dest: "{{ stats_prometheus_config_directory }}/prometheus.yml"
|
|
register: prometheus_config
|
|
|
|
- name: Prometheus Docker Container
|
|
community.docker.docker_container:
|
|
name: "{{ stats_prometheus_container_name }}"
|
|
image: "{{ stats_prometheus_image_name }}:{{ stats_prometheus_image_version }}"
|
|
pull: true
|
|
volumes:
|
|
- "{{ stats_prometheus_config_directory }}/prometheus.yml:/etc/prometheus/prometheus.yml:ro"
|
|
- "{{ stats_prometheus_data_directory }}:/prometheus:rw"
|
|
- "/etc/timezone:/etc/timezone:ro"
|
|
ports:
|
|
- "{{ stats_prometheus_port }}:9090"
|
|
restart_policy: unless-stopped
|
|
memory: "{{ stats_prometheus_memory }}"
|
|
restart: "{{ prometheus_config is changed }}"
|
|
command: "--config.file=/etc/prometheus/prometheus.yml --storage.tsdb.retention.size={{ stats_prometheus_retention_size }} --storage.tsdb.retention.time={{ stats_prometheus_retention_time }}"
|
|
labels:
|
|
traefik.enable: "{{ stats_prometheus_available_externally | string }}"
|
|
traefik.http.routers.prometheus.rule: "Host(`{{ stats_prometheus_hostname }}.{{ ansible_nas_domain }}`)"
|
|
traefik.http.routers.prometheus.tls.certresolver: "letsencrypt"
|
|
traefik.http.routers.prometheus.tls.domains[0].main: "{{ ansible_nas_domain }}"
|
|
traefik.http.routers.prometheus.tls.domains[0].sans: "*.{{ ansible_nas_domain }}"
|
|
traefik.http.services.prometheus.loadbalancer.server.port: "9090"
|
|
homepage.group: Monitoring
|
|
homepage.name: Prometheus
|
|
homepage.icon: prometheus
|
|
homepage.href: "http://{{ hostvars[inventory_hostname]['ansible_default_ipv4']['address'] }}:{{ stats_prometheus_port }}"
|
|
homepage.description: Metrics and alerting
|
|
homepage.widget.type: prometheus
|
|
homepage.widget.url: "http://{{ hostvars[inventory_hostname]['ansible_default_ipv4']['address'] }}:{{ stats_prometheus_port }}"
|
|
when: stats_enabled is true
|
|
|
|
- name: Stop Prometheus
|
|
block:
|
|
- name: Stop Prometheus
|
|
community.docker.docker_container:
|
|
name: "{{ stats_prometheus_container_name }}"
|
|
state: absent
|
|
when: stats_enabled is false
|