ansible/roles/grafana/tasks/main.yml
Salt cc814b3cb6 Add Grafana
WEW No fires
2020-05-10 03:30:19 -05:00

75 lines
2.2 KiB
YAML

#!/usr/bin/ansible-playbook
# vim:ft=ansible:
---
- name: Install, configure, and start Grafana
block:
- name: Create and configure DB
block:
- name: Create DB
mysql_db:
name: grafana
login_user: root
login_password: "{{ mysql_root_password }}"
state: present
- name: Create user
mysql_user:
name: grafana
host: localhost
password: "{{ grafana_mysql_password }}"
priv: "grafana.*:ALL,GRANT"
login_user: root
login_password: "{{ mysql_root_password }}"
- name: Set up Apache
block:
- name: Enable modules
command:
cmd: a2enmod "{{ item }}"
creates: "/etc/apache2/mods-enabled/{{ item }}.load"
loop:
- proxy
- proxy_http
notify: restart apache
- name: Template out vhost
template:
src: "apache2-vhost-ssl.conf"
dest: "/etc/apache2/sites-available/{{ grafana_url }}.conf"
notify: restart apache
- name: Create webroot
file:
state: directory
path: "{{ grafana_webroot }}"
- name: Enable site
command:
cmd: "a2ensite {{ grafana_url }}.conf"
creates: "/etc/apache2/sites-enabled/{{ grafana_url }}.conf"
notify: restart apache
- name: Generate certificate
include_role:
name: https
vars:
website_url: "{{ grafana_url }}"
- name: Add and configure packages
block:
- name: Add APT signing key
apt_key:
url: "https://packages.grafana.com/gpg.key"
- name: Add APT repo
apt_repository:
repo: "deb https://packages.grafana.com/oss/deb stable main"
- name: Install Grafana
apt:
name:
- grafana
- name: Configure Grafana
template:
src: "grafana.ini"
dest: "/etc/grafana/grafana.ini"
mode: "0640"
- name: Enable Grafana
systemd:
daemon_reload: yes
name: "grafana-server.service"
enabled: yes
state: "started"
become: yes