85 lines
2.6 KiB
YAML
85 lines
2.6 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: 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
|
|
block:
|
|
- name: Template out main config
|
|
template:
|
|
src: "grafana.ini"
|
|
dest: "/etc/grafana/grafana.ini"
|
|
mode: "0640"
|
|
notify: restart grafana
|
|
- name: Clone configuration repo
|
|
git:
|
|
repo: "{{ grafana.config_repo }}"
|
|
dest: "/etc/grafana/provisioning"
|
|
force: yes
|
|
notify: restart grafana
|
|
when: grafana.config_repo is defined
|
|
- name: Enable Grafana
|
|
systemd:
|
|
daemon_reload: yes
|
|
name: "grafana-server.service"
|
|
enabled: yes
|
|
state: "started"
|
|
- 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 }}"
|
|
become: yes
|