Skip to content

Commit 611711f

Browse files
committed
Implement global handlers
There are tasks that are doing things with other tools of the collection (e.g: after changing certificates in elasticsearch, we need to restart kibana). This tasks will be moved to the global role "elasticstack" and can be called by via 'notify'. Also, global handlers will only do something when `elasticstack_collection_managed` is true (means the whole stack is managed by the collecion)
1 parent 62e7463 commit 611711f

File tree

6 files changed

+27
-24
lines changed

6 files changed

+27
-24
lines changed

roles/elasticsearch/handlers/main.yml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,3 @@
88
- elasticsearch_enable | bool
99
- not elasticsearch_freshstart.changed | bool
1010
- not elasticsearch_freshstart_security.changed | bool
11-
12-
- name: Restart kibana if available for elasticsearch certificates
13-
ansible.builtin.include_tasks: handlers/restart_kibana.yml
14-
with_items: "{{ groups[elasticstack_kibana_group_name] }}"
15-
when:
16-
- elasticstack_collection_managed: true
17-
- "not 'renew_ca' in ansible_run_tags"
18-
- "not elasticstack_ca_will_expire_soon | bool"
19-
- elasticstack_kibana_group_name is defined
20-
- groups[elasticstack_kibana_group_name] is defined

roles/elasticsearch/handlers/restart_kibana.yml

Lines changed: 0 additions & 12 deletions
This file was deleted.

roles/elasticsearch/tasks/elasticsearch-security.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@
303303
mode: 0640
304304
notify:
305305
- Restart Elasticsearch
306-
- Restart kibana if available for elasticsearch certificates
306+
- "Global - Restart Kibana"
307307
tags:
308308
- certificates
309309
- renew_ca
@@ -319,7 +319,7 @@
319319
mode: 0640
320320
notify:
321321
- Restart Elasticsearch
322-
- Restart kibana if available for elasticsearch certificates
322+
- Global - Restart Kibana
323323
tags:
324324
- certificates
325325
- renew_ca

roles/elasticstack/defaults/main.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ elasticstack_elasticsearch_group_name: elasticsearch
33
elasticstack_logstash_group_name: logstash
44
elasticstack_kibana_group_name: kibana
55

6+
elasticstack_hosts_elasticsearch: groups[elasticstack_elasticsearch_group_name]
7+
elasticstack_hosts_logstash: groups[elasticstack_logstash_group_name]
8+
elasticstack_hosts_kibana: groups[elasticstack_kibana_group_name]
9+
610
elasticstack_beats_port: 5044
711
elasticstack_ca_host: "{{ groups[elasticstack_elasticsearch_group_name][0] }}"
812
elasticstack_ca_dir: /opt/es-ca
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
- name: "Global - Restart Kibana"
3+
ansible.builtin.include_tasks: tasks/global/restart_kibana.yml
4+
with_items: "{{ elasticstack_hosts_kibana }}"
5+
when:
6+
- elasticstack_collection_managed | bool # Only restart if all is managed by the collection
7+
- elasticstack_hosts_kibana | length > 0
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
- name: Restart Kibana (if installed)
3+
delegate_to: "{{ item }}"
4+
block:
5+
- name: Fetch installed packages
6+
ansible.builtin.package_facts:
7+
manager: "auto"
8+
changed_when: false
9+
10+
- name: Restart Kibana
11+
ansible.builtin.service:
12+
name: kibana
13+
state: restarted
14+
when: "'kibana' in ansible_facts.packages"

0 commit comments

Comments
 (0)