Skip to content
This repository was archived by the owner on Jun 24, 2022. It is now read-only.

Commit ce18052

Browse files
author
Dale McDiarmid
committed
Single template file
1 parent 979ef94 commit ce18052

4 files changed

+18
-21
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ Converging
77
TODO
88
.idea/
99
elasticsearch.iml
10+
!/vars/RedHat.yml

tasks/elasticsearch-template-copy.yml

-9
This file was deleted.

tasks/elasticsearch-template-insert.yml tasks/elasticsearch-template.yml

+14-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
1-
#Templates done after restart therefore. e.g. suppose user removes security on a running node and doesn't specify es_api_basic_auth_username and es_api_basic_auth_password. The templates will subsequently not be removed if we don't wait for the node to restart.
1+
---
2+
3+
- file: path=/etc/elasticsearch/templates state=directory owner={{ es_user }} group={{ es_group }}
4+
5+
- name: Copy templates to elasticsearch
6+
copy: src={{ item }} dest=/etc/elasticsearch/templates owner={{ es_user }} group={{ es_group }}
7+
register: load_templates
8+
with_fileglob:
9+
- "{{ es_templates_fileglob | default('') }}"
10+
211

312
- name: Ensure elasticsearch is started
413
service: name={{instance_init_script | basename}} state=started enabled=yes
5-
when: es_start_service
14+
when: es_start_service and load_templates.changed
615

716
- name: Wait for elasticsearch to startup
817
wait_for: host={{es_api_host}} port={{es_api_port}} delay=10
9-
when: es_start_service
18+
when: es_start_service and load_templates.changed
1019

1120
- name: Install templates without auth
1221
uri:
@@ -15,7 +24,7 @@
1524
status_code: 200
1625
body_format: json
1726
body: "{{ lookup('file', item) }}"
18-
when: es_start_service and not es_enable_xpack or not es_xpack_features is defined or "security" not in es_xpack_features
27+
when: load_templates.changed and es_start_service and not es_enable_xpack or not es_xpack_features is defined or "security" not in es_xpack_features
1928
with_fileglob:
2029
- "{{ es_templates_fileglob | default('') }}"
2130
run_once: True
@@ -30,7 +39,7 @@
3039
force_basic_auth: yes
3140
body_format: json
3241
body: "{{ lookup('file', item) }}"
33-
when: es_start_service and es_enable_xpack and es_xpack_features is defined and "security" in es_xpack_features
42+
when: load_templates.changed and es_start_service and es_enable_xpack and es_xpack_features is defined and "security" in es_xpack_features
3443
with_fileglob:
3544
- "{{ es_templates_fileglob | default('') }}"
3645
run_once: True

tasks/main.yml

+3-7
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,11 @@
3737
tags:
3838
- xpack
3939

40-
- include: elasticsearch-template-copy.yml
41-
when: es_templates
42-
tags:
43-
- templates
44-
4540
- meta: flush_handlers
4641

47-
- include: elasticsearch-template-insert.yml
48-
when: load_templates
42+
#Templates done after restart - handled by flushing the handlers. e.g. suppose user removes security on a running node and doesn't specify es_api_basic_auth_username and es_api_basic_auth_password. The templates will subsequently not be removed if we don't wait for the node to restart.
43+
- include: elasticsearch-template.yml
44+
when: es_templates
4945
tags:
5046
- templates
5147

0 commit comments

Comments
 (0)