ansible-nas/roles/stats/tasks/grafana.yml

70 lines
2.9 KiB
YAML
Raw Normal View History

---
2023-03-10 21:00:37 +00:00
- name: Start Grafana
block:
- name: Create Grafana Directories
ansible.builtin.file:
path: "{{ item }}"
state: directory
owner: "472"
recurse: yes
2023-03-11 12:21:09 +00:00
changed_when: false
2023-03-10 21:00:37 +00:00
with_items:
- "{{ stats_grafana_data_directory }}"
- "{{ stats_grafana_config_directory }}"
- "{{ stats_grafana_config_directory }}/dashboards"
- "{{ stats_grafana_config_directory }}/provisioning/datasources"
- "{{ stats_grafana_config_directory }}/provisioning/dashboards"
2023-03-10 21:00:37 +00:00
- name: Template Grafana data source
ansible.builtin.template:
src: datasources/ansible-nas.yml
dest: "{{ stats_grafana_config_directory }}/provisioning/datasources/ansible-nas.yml"
2023-03-10 21:00:37 +00:00
- name: Copy Grafana dashboards configuration
ansible.builtin.copy:
src: dashboards/ansible-nas.yml
dest: "{{ stats_grafana_config_directory }}/provisioning/dashboards/ansible-nas.yml"
2023-03-10 21:00:37 +00:00
- name: Copy Grafana Ansible-NAS dashboard
ansible.builtin.copy:
src: dashboards/ansible-nas-overview.json
dest: "{{ stats_grafana_config_directory }}/dashboards/ansible-nas-overview.json"
2023-03-10 21:00:37 +00:00
- name: Grafana Docker Container
community.docker.docker_container:
name: "{{ stats_grafana_container_name }}"
image: "{{ stats_grafana_image_name }}:{{ stats_grafana_image_version }}"
pull: true
volumes:
- "{{ stats_grafana_data_directory }}:/var/lib/grafana:rw"
- "{{ stats_grafana_config_directory }}/provisioning:/etc/grafana/provisioning:ro"
- "{{ stats_grafana_config_directory }}/dashboards:/etc/dashboards:ro"
ports:
- "{{ stats_grafana_port }}:3000"
env:
GF_PLUGINS_ENABLE_ALPHA: "true"
GF_UNIFIED_ALERTING_ENABLED: "true"
restart_policy: unless-stopped
memory: 1g
labels:
traefik.enable: "{{ stats_grafana_available_externally | string }}"
traefik.http.routers.grafana.rule: "Host(`grafana.{{ ansible_nas_domain }}`) "
traefik.http.routers.grafana.tls.certresolver: "letsencrypt"
traefik.http.routers.grafana.tls.domains[0].main: "{{ ansible_nas_domain }}"
traefik.http.routers.grafana.tls.domains[0].sans: "*.{{ ansible_nas_domain }}"
traefik.http.services.grafana.loadbalancer.server.port: "3000"
2024-02-26 17:05:32 +00:00
homepage.group: Monitoring
homepage.name: Grafana
homepage.icon: grafana
homepage.href: "http://{{ hostvars[inventory_hostname]['ansible_default_ipv4']['address'] }}:{{ stats_grafana_port }}"
homepage.description: Dashboards and centralized observability.
2023-03-10 21:00:37 +00:00
when: stats_enabled is true
- name: Stop Grafana
block:
- name: Stop Grafana
community.docker.docker_container:
name: "{{ stats_grafana_container_name }}"
state: absent
when: stats_enabled is false