From b818249d825916459f8b5a83293ee9e2985db3af Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Fri, 27 Sep 2024 16:14:23 +0200 Subject: [PATCH] Add grafana role --- roles/grafana/handlers/main.yml | 11 +++++++++++ roles/grafana/tasks/main.yml | 28 +++++++++++++++++++++++++++ roles/grafana/templates/nginx.conf.j2 | 13 +++++++++++++ 3 files changed, 52 insertions(+) create mode 100644 roles/grafana/handlers/main.yml create mode 100644 roles/grafana/tasks/main.yml create mode 100644 roles/grafana/templates/nginx.conf.j2 diff --git a/roles/grafana/handlers/main.yml b/roles/grafana/handlers/main.yml new file mode 100644 index 0000000..c60fc36 --- /dev/null +++ b/roles/grafana/handlers/main.yml @@ -0,0 +1,11 @@ +- name: restart grafana + service: + name: grafana + state: restarted + when: "'handler' not in ansible_skip_tags" + +- name: reload nginx + service: + name: nginx + state: reloaded + when: "'handler' not in ansible_skip_tags" diff --git a/roles/grafana/tasks/main.yml b/roles/grafana/tasks/main.yml new file mode 100644 index 0000000..79dba4e --- /dev/null +++ b/roles/grafana/tasks/main.yml @@ -0,0 +1,28 @@ +- name: Install packages + package: + name: grafana + +- name: Configure grafana + ini_file: + path: /etc/grafana.ini + section: '{{ item.section | default("") }}' + option: '{{ item.option }}' + value: '{{ item.value }}' + loop: + - { section: analytics, option: reporting_enabled, value: false } + - { section: analytics, option: check_for_updates, value: false } + - { section: analytics, option: check_for_plugin_updates, value: false } + - { section: news, option: news_feed_enabled, value: false } + - { section: public_dashboards, option: enabled, value: false } + +- name: Set up nginx site + template: + dest: '/etc/nginx/http.d/grafana.conf' + src: 'nginx.conf.j2' + notify: reload nginx + +- name: Enable grafana + service: + name: grafana + enabled: yes + state: started diff --git a/roles/grafana/templates/nginx.conf.j2 b/roles/grafana/templates/nginx.conf.j2 new file mode 100644 index 0000000..63ac1e1 --- /dev/null +++ b/roles/grafana/templates/nginx.conf.j2 @@ -0,0 +1,13 @@ +server { + listen 443 ssl; + listen [::]:443 ssl; + server_name {{ dns_name }}; + + ssl_certificate /etc/letsencrypt/live/{{ dns_name }}/fullchain.pem; + ssl_certificate_key /etc/letsencrypt/live/{{ dns_name }}/privkey.pem; + + location / { + proxy_pass http://localhost:3000; + proxy_set_header Host $host; + } +}