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

76 lines
1.7 KiB
YAML
Raw Normal View History

- name: Install GPG package
package:
name: gpg
state: present
- name: Add Grafana GPG apt key
2020-04-13 14:46:45 +02:00
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
2020-04-13 14:46:45 +02:00
- name: Update apt cache
apt:
update_cache: yes
cache_valid_time: 3600
when: grafana_repo is changed
2020-04-13 14:46:45 +02:00
- name: Install grafana package
package:
name: grafana
state: present
notify: restart grafana
2020-04-13 14:46:45 +02:00
- name: Copy Grafana config
2020-04-13 14:46:45 +02:00
template:
src: grafana.ini.j2
dest: /etc/grafana/grafana.ini
notify: restart grafana
- name: Start and enable Grafana service
2020-04-13 14:46:45 +02:00
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
2020-04-13 14:46:45 +02:00
file:
path: "{{ nginx_config_dir }}/{{ inventory_hostname }}.d"
state: directory
- name: Configure Nginx for Grafana
include_role:
2020-04-13 14:46:45 +02:00
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: /