ansible-infra/roles/monitoring/tasks/grafana.yml

76 lines
1.7 KiB
YAML

- name: Install GPG package
package:
name: gpg
state: present
- name: Add Grafana GPG apt key
apt_key:
url: https://packages.grafana.com/gpg.key
state: present
- name: Add Grafana repository
apt_repository:
repo: deb https://packages.grafana.com/oss/deb stable main
state: present
register: grafana_repo
notify: restart grafana
- name: Update apt cache
apt:
update_cache: yes
cache_valid_time: 3600
when: grafana_repo is changed
- name: Install grafana package
package:
name: grafana
state: present
notify: restart grafana
- name: Copy Grafana config
template:
src: grafana.ini.j2
dest: /etc/grafana/grafana.ini
notify: restart grafana
- name: Start and enable Grafana service
systemd:
name: grafana-server
state: started
enabled: yes
register: grafana_service
- name: Configure Nginx for Grafana
import_role:
name: nginx
vars:
nginx_config_file: "{{ inventory_hostname }}.conf"
nginx_server:
name: "{{ inventory_hostname }}"
port: 80
locations:
- path: "= /"
return:
code: 301
url: "http://{{ inventory_hostname }}{{ grafana_web_path }}"
includes:
- "{{ nginx_config_dir }}/{{ inventory_hostname }}.d/*.conf"
- name: Ensure Nginx config directory exists
file:
path: "{{ nginx_config_dir }}/{{ inventory_hostname }}.d"
state: directory
- name: Configure Nginx for Grafana
include_role:
name: nginx
tasks_from: configure
vars:
nginx_config_file: "{{ inventory_hostname }}.d/grafana.conf"
nginx_server:
locations:
- path: "{{ grafana_web_path }}/"
proxy_pass:
port: "{{ grafana_port }}"
path: /