2020-05-10 03:30:19 -05:00
|
|
|
#!/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
|
2020-08-02 19:36:46 -05:00
|
|
|
login_password: "{{ mysql.root_password }}"
|
2020-05-10 03:30:19 -05:00
|
|
|
state: present
|
|
|
|
- name: Create user
|
|
|
|
mysql_user:
|
|
|
|
name: grafana
|
|
|
|
host: localhost
|
2020-08-02 19:40:39 -05:00
|
|
|
password: "{{ grafana.mysql_password }}"
|
2020-05-10 03:30:19 -05:00
|
|
|
priv: "grafana.*:ALL,GRANT"
|
|
|
|
login_user: root
|
2020-08-02 19:36:46 -05:00
|
|
|
login_password: "{{ mysql.root_password }}"
|
2020-08-07 04:35:04 -05:00
|
|
|
- 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
|
2020-08-07 04:35:29 -05:00
|
|
|
block:
|
|
|
|
- name: Template out main config
|
|
|
|
template:
|
|
|
|
src: "grafana.ini"
|
|
|
|
dest: "/etc/grafana/grafana.ini"
|
|
|
|
mode: "0640"
|
2020-08-07 04:35:04 -05:00
|
|
|
- name: Enable Grafana
|
|
|
|
systemd:
|
|
|
|
daemon_reload: yes
|
|
|
|
name: "grafana-server.service"
|
|
|
|
enabled: yes
|
|
|
|
state: "started"
|
2020-05-10 03:30:19 -05:00
|
|
|
- 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"
|
2020-08-02 19:40:39 -05:00
|
|
|
dest: "/etc/apache2/sites-available/{{ grafana.url }}.conf"
|
2020-05-10 03:30:19 -05:00
|
|
|
notify: restart apache
|
|
|
|
- name: Create webroot
|
|
|
|
file:
|
|
|
|
state: directory
|
2020-08-02 19:40:39 -05:00
|
|
|
path: "{{ grafana.webroot }}"
|
2020-05-10 03:30:19 -05:00
|
|
|
- name: Enable site
|
|
|
|
command:
|
2020-08-02 19:40:39 -05:00
|
|
|
cmd: "a2ensite {{ grafana.url }}.conf"
|
|
|
|
creates: "/etc/apache2/sites-enabled/{{ grafana.url }}.conf"
|
2020-05-10 03:30:19 -05:00
|
|
|
notify: restart apache
|
|
|
|
- name: Generate certificate
|
|
|
|
include_role:
|
|
|
|
name: https
|
|
|
|
vars:
|
2020-08-02 19:40:39 -05:00
|
|
|
website_url: "{{ grafana.url }}"
|
2020-05-10 03:30:19 -05:00
|
|
|
become: yes
|