diff --git a/roles/grafana_agent/handlers/main.yaml b/roles/grafana_agent/handlers/main.yaml index a221474..b56de06 100644 --- a/roles/grafana_agent/handlers/main.yaml +++ b/roles/grafana_agent/handlers/main.yaml @@ -3,6 +3,7 @@ ansible.builtin.service: name: grafana-agent state: restarted + daemon_reload: true enabled: true listen: Restart grafana-agent when: not ansible_check_mode diff --git a/roles/grafana_server/defaults/main.yaml b/roles/grafana_server/defaults/main.yaml index 5dbd5e2..b183e4b 100644 --- a/roles/grafana_server/defaults/main.yaml +++ b/roles/grafana_server/defaults/main.yaml @@ -5,6 +5,7 @@ grafana_server_install: true grafana_server_data_dir: /var/lib/grafana grafana_server_install_nginx_config: false grafana_server_external_domain: grafana.local.mainnet.community +grafana_server_external_proto: https grafana_server_enabled_plugins: - grafana-sentry-datasource diff --git a/roles/grafana_server/handlers/main.yaml b/roles/grafana_server/handlers/main.yaml new file mode 100644 index 0000000..78e51ec --- /dev/null +++ b/roles/grafana_server/handlers/main.yaml @@ -0,0 +1,7 @@ +--- +- name: Restart the grafana server + ansible.builtin.systemd: + state: restarted + enabled: true + daemon_reload: true + name: grafana-server diff --git a/roles/grafana_server/tasks/main.yaml b/roles/grafana_server/tasks/main.yaml index 8d2aa07..486f8c6 100644 --- a/roles/grafana_server/tasks/main.yaml +++ b/roles/grafana_server/tasks/main.yaml @@ -18,6 +18,7 @@ retries: 3 delay: 3 until: grafana_server_install is succeeded + notify: "Restart the grafana server" - name: Ensure grafana plugins dir exists ansible.builtin.file: @@ -35,19 +36,11 @@ changed_when: false with_items: "{{ grafana_server_enabled_plugins }}" - - name: Grafana Server | Template a grafana-server config - ansible.builtin.template: - src: etc/grafana/grafana.ini.j2 - dest: /etc/grafana/grafana.ini - owner: grafana - group: grafana - mode: '0644' - register: grafana_config_tmpl - - - name: Grafana Server | Restart the grafana service when required - ansible.builtin.systemd: - state: restarted - enabled: true - daemon_reload: true - name: grafana-server - when: not ansible_check_mode and (grafana_config_tmpl.changed or grafana_server_install.changed) +- name: Grafana Server | Template a grafana-server config + ansible.builtin.template: + src: etc/grafana/grafana.ini.j2 + dest: /etc/grafana/grafana.ini + owner: grafana + group: grafana + mode: '0644' + notify: "Restart the grafana server" diff --git a/roles/grafana_server/templates/etc/grafana/grafana.ini.j2 b/roles/grafana_server/templates/etc/grafana/grafana.ini.j2 index 3c677d0..b660802 100644 --- a/roles/grafana_server/templates/etc/grafana/grafana.ini.j2 +++ b/roles/grafana_server/templates/etc/grafana/grafana.ini.j2 @@ -45,7 +45,9 @@ plugins = {{ grafana_server_data_dir }}/plugins http_port = 3000 # The public facing domain name used to access grafana from a browser -;domain = localhost +{% if grafana_server_external_domain | length > 0 %} +domain = {{ grafana_server_external_domain }} +{% endif %} # Redirect to correct domain if host header does not match domain # Prevents DNS rebinding attacks @@ -53,7 +55,9 @@ http_port = 3000 # The full public facing url you use in browser, used for redirects and emails # If you use reverse proxy and sub path specify full url (with sub path) -;root_url = %(protocol)s://%(domain)s:%(http_port)s/ +{% if grafana_server_external_domain | length > 0 %} +root_url = {{ grafana_server_external_proto -}}://%(domain)s/ +{% endif %} # Serve Grafana from subpath specified in `root_url` setting. By default it is set to `false` for compatibility reasons. ;serve_from_sub_path = false