From 95b73daa36b23565a8566f71f9b202d3459b685f Mon Sep 17 00:00:00 2001 From: Sam Chudnick Date: Sun, 25 Jun 2023 09:52:36 -0400 Subject: Initial Commit --- .../services/monitoring/grafana/defaults/main.yml | 5 + .../services/monitoring/grafana/handlers/main.yml | 13 +++ roles/services/monitoring/grafana/tasks/main.yml | 125 +++++++++++++++++++++ 3 files changed, 143 insertions(+) create mode 100644 roles/services/monitoring/grafana/defaults/main.yml create mode 100644 roles/services/monitoring/grafana/handlers/main.yml create mode 100644 roles/services/monitoring/grafana/tasks/main.yml (limited to 'roles/services/monitoring/grafana') diff --git a/roles/services/monitoring/grafana/defaults/main.yml b/roles/services/monitoring/grafana/defaults/main.yml new file mode 100644 index 0000000..c346e54 --- /dev/null +++ b/roles/services/monitoring/grafana/defaults/main.yml @@ -0,0 +1,5 @@ +grafana_package: + - grafana + - nginx +grafana_config: files/grafana_config/ +grafana_data: files/grafana.db diff --git a/roles/services/monitoring/grafana/handlers/main.yml b/roles/services/monitoring/grafana/handlers/main.yml new file mode 100644 index 0000000..8026c6d --- /dev/null +++ b/roles/services/monitoring/grafana/handlers/main.yml @@ -0,0 +1,13 @@ +- name: update repos + apt: + update_cache: yes + +- name: restart grafana + service: + name: grafana-server + state: restarted + +- name: restart nginx + service: + name: nginx + state: restarted diff --git a/roles/services/monitoring/grafana/tasks/main.yml b/roles/services/monitoring/grafana/tasks/main.yml new file mode 100644 index 0000000..e9f824e --- /dev/null +++ b/roles/services/monitoring/grafana/tasks/main.yml @@ -0,0 +1,125 @@ +- name: install extrepo + package: + name: extrepo + state: latest + +- name: add Grafana repo + register: result + changed_when: result.stdout | regex_search("skipped") | bool + notify: update repos + command: + cmd: extrepo enable grafana + creates: /etc/apt/sources.list.d/extrepo_grafana.sources + +- meta: flush_handlers + +- name: update Grafana repo + changed_when: false + command: + cmd: extrepo update grafana + +- name: install grafana + package: + name: "{{ grafana_package }}" + +- name: deploy grafana config + notify: restart grafana + template: + src: "{{ grafana_config }}" + dest: /etc/grafana/grafana.ini + owner: root + group: grafana + mode: '0640' + +- name: deploy nginx configuration + notify: restart nginx + copy: + src: "{{ grafana_nginx_config }}" + dest: /etc/nginx/sites-available/grafana.conf + owner: root + group: root + mode: '0644' + +- name: symlink site + notify: restart nginx + file: + src: /etc/nginx/sites-available/grafana.conf + dest: /etc/nginx/sites-enabled/grafana.conf + owner: root + group: root + state: link + +- name: allow http (80/tcp) traffic + ufw: + rule: allow + port: '80' + proto: tcp + +- name: allow https (443/tcp) traffic + ufw: + rule: allow + port: '443' + proto: tcp + +- name: enable grafana + systemd: + daemon_reload: yes + enabled: yes + masked: no + name: grafana-server + +- meta: flush_handlers + +- name: add grafana user + ignore_errors: yes + community.grafana.grafana_user: + name: "{{ grafana_admin }}" + email: "{{ grafana_email }}" + url: "{{ grafana_url }}" + login: "{{ grafana_admin }}" + password: "{{ grafana_password }}" + is_admin: true + state: present + +- name: add prometheus datasource + community.grafana.grafana_datasource: + grafana_url: "{{ grafana_url }}" + grafana_user: "{{ grafana_admin }}" + grafana_password: "{{ grafana_password }}" + name: "Prometheus" + ds_type: prometheus + ds_url: "{{ prometheus_url }}" + access: proxy + +- name: add influxdb datasource + community.grafana.grafana_datasource: + grafana_url: "{{ grafana_url }}" + grafana_user: "{{ grafana_admin }}" + grafana_password: "{{ grafana_password }}" + name: "Proxmox InfluxDB" + ds_type: influxdb + ds_url: "{{ influxdb_url }}" + database: "{{ influx_database }}" + user: "{{ influx_user }}" + password: "{{ influx_password }}" + access: proxy + +- name: add loki datasource + community.grafana.grafana_datasource: + grafana_url: "{{ grafana_url }}" + grafana_user: "{{ grafana_admin }}" + grafana_password: "{{ grafana_password }}" + name: "Loki" + ds_type: loki + ds_url: "{{ loki_url }}" + access: proxy + +- name: import main custom dashboard + delegate_to: localhost + become: no + community.grafana.grafana_dashboard: + grafana_url: "{{ grafana_url }}" + grafana_user: "{{ grafana_admin }}" + grafana_password: "{{ grafana_password }}" + path: "{{ grafana_dashboard_main }}" + overwrite: yes -- cgit v1.2.3