2020-12-02 17:22:59 +01:00
|
|
|
- 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
|
|
|
|
|
2020-12-02 17:22:59 +01:00
|
|
|
- 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
|
|
|
|
2020-12-02 17:22:59 +01: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
|
|
|
|
2020-12-02 17:22:59 +01:00
|
|
|
- name: Install grafana package
|
|
|
|
package:
|
|
|
|
name: grafana
|
|
|
|
state: present
|
|
|
|
notify: restart grafana
|
2020-04-13 14:46:45 +02:00
|
|
|
|
2020-12-02 17:22:59 +01: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
|
|
|
|
|
2020-12-02 17:22:59 +01:00
|
|
|
- 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"
|
|
|
|
|
2020-12-02 17:22:59 +01:00
|
|
|
- name: Ensure Nginx config directory exists
|
2020-04-13 14:46:45 +02:00
|
|
|
file:
|
|
|
|
path: "{{ nginx_config_dir }}/{{ inventory_hostname }}.d"
|
|
|
|
state: directory
|
|
|
|
|
2020-12-02 17:22:59 +01:00
|
|
|
- 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: /
|