Skip to content

Commit

Permalink
fix: external url for the grafana
Browse files Browse the repository at this point in the history
  • Loading branch information
ehh-why-its-so-hard committed Dec 8, 2024
1 parent ae82e08 commit 004d246
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 18 deletions.
1 change: 1 addition & 0 deletions roles/grafana_agent/handlers/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions roles/grafana_server/defaults/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 7 additions & 0 deletions roles/grafana_server/handlers/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
- name: Restart the grafana server
ansible.builtin.systemd:
state: restarted
enabled: true
daemon_reload: true
name: grafana-server
25 changes: 9 additions & 16 deletions roles/grafana_server/tasks/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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"
8 changes: 6 additions & 2 deletions roles/grafana_server/templates/etc/grafana/grafana.ini.j2
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,19 @@ 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
;enforce_domain = false

# 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
Expand Down

0 comments on commit 004d246

Please sign in to comment.