Skip to content

Commit 27b5757

Browse files
committed
Control grafana service state
1 parent 97aa210 commit 27b5757

File tree

5 files changed

+15
-5
lines changed

5 files changed

+15
-5
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ All variables which can be overridden are stored in [defaults/main.yml](defaults
5959
| `grafana_environment` | {} | Optional Environment param for Grafana installation, useful ie for setting http_proxy |
6060
| `grafana_plugins` | [] | List of Grafana plugins which should be installed |
6161
| `grafana_alert_notifications` | [] | List of alert notification channels to be created, updated, or deleted |
62-
62+
| `grafana_state` | `started` | Grafana service state after this role, either `started` or `stopped` (restarts will happen as required for changed configuration etc. only in `started` mode) |
63+
| `grafana_enabled` | true | Whether Grafana service is enabled on restart |
6364
Datasource example:
6465

6566
```yaml

defaults/main.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,3 +251,7 @@ grafana_environment: {}
251251
grafana_panels: {}
252252
# disable_sanitize_html: false
253253
# enable_alpha: false
254+
255+
# Control service state
256+
grafana_enabled: true
257+
grafana_state: started

handlers/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
service:
55
name: grafana-server
66
state: restarted
7+
when: "grafana_state != 'stopped'"
78
tags:
89
- grafana_run
910

tasks/configure.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,6 @@
8282
- name: Enable and start Grafana systemd unit
8383
systemd:
8484
name: grafana-server
85-
enabled: true
86-
state: started
85+
enabled: "{{ grafana_enabled }}"
86+
state: "{{ 'stopped' if grafana_state == 'stopped' else 'started' }}"
8787
daemon_reload: true

tasks/main.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@
5151
wait_for:
5252
host: "{{ grafana_address }}"
5353
port: "{{ grafana_port }}"
54-
when: grafana_server.protocol is undefined or grafana_server.protocol in ['http', 'https']
54+
when:
55+
- grafana_state != 'stopped'
56+
- grafana_server.protocol is undefined or grafana_server.protocol in ['http', 'https']
5557
tags:
5658
- grafana_install
5759
- grafana_configure
@@ -63,7 +65,9 @@
6365
- name: Wait for grafana to start (socket)
6466
wait_for:
6567
path: "{{ grafana_server.socket }}"
66-
when: grafana_server.protocol is defined and grafana_server.protocol == 'socket'
68+
when:
69+
- grafana_state != 'stopped'
70+
- grafana_server.protocol is defined and grafana_server.protocol == 'socket'
6771
tags:
6872
- grafana_install
6973
- grafana_configure

0 commit comments

Comments
 (0)