|
1 | 1 | ---
|
2 | 2 |
|
3 |
| -- name: Create keystore |
| 3 | +- name: "Elasticsearch keystore: Create keystore" |
4 | 4 | ansible.builtin.command: /usr/share/elasticsearch/bin/elasticsearch-keystore create
|
5 | 5 | args:
|
6 | 6 | creates: /etc/elasticsearch/elasticsearch.keystore
|
7 | 7 |
|
8 |
| -- name: Check for bootstrap password |
| 8 | +- name: "Elasticsearch keystore: Get current variables" |
9 | 9 | ansible.builtin.command: /usr/share/elasticsearch/bin/elasticsearch-keystore list
|
10 | 10 | changed_when: false
|
11 |
| - register: elasticsearch_keystore |
12 |
| - |
13 |
| -- name: Set bootstrap password # noqa: risky-shell-pipe |
14 |
| - ansible.builtin.shell: > |
15 |
| - if test -n "$(ps -p $$ | grep bash)"; then set -o pipefail; fi; |
16 |
| - echo "{{ elasticsearch_bootstrap_pw }}" | |
17 |
| - /usr/share/elasticsearch/bin/elasticsearch-keystore |
18 |
| - add -x 'bootstrap.password' |
19 |
| - when: "'bootstrap.password' not in elasticsearch_keystore.stdout_lines" |
20 |
| - changed_when: false |
21 |
| - no_log: true |
22 |
| - notify: |
23 |
| - - Restart Elasticsearch |
24 |
| - ignore_errors: "{{ ansible_check_mode }}" |
25 |
| - |
26 |
| -- name: Get xpack.security.http.ssl.keystore.secure_password # noqa: risky-shell-pipe |
27 |
| - ansible.builtin.shell: > |
28 |
| - if test -n "$(ps -p $$ | grep bash)"; then set -o pipefail; fi; |
29 |
| - /usr/share/elasticsearch/bin/elasticsearch-keystore |
30 |
| - show 'xpack.security.http.ssl.keystore.secure_password' |
31 |
| - when: |
32 |
| - - "'xpack.security.http.ssl.keystore.secure_password' in elasticsearch_keystore.stdout_lines" |
33 |
| - - elasticsearch_http_security |
34 |
| - register: elasticsearch_http_ssl_keystore_secure_password |
35 |
| - ignore_errors: "{{ ansible_check_mode }}" |
36 |
| - no_log: true |
37 |
| - changed_when: false |
38 |
| - |
39 |
| -- name: Set xpack.security.http.ssl.keystore.secure_password # noqa: risky-shell-pipe |
40 |
| - ansible.builtin.shell: > |
41 |
| - if test -n "$(ps -p $$ | grep bash)"; then set -o pipefail; fi; |
42 |
| - echo "{{ elasticsearch_tls_key_passphrase }}" | |
43 |
| - /usr/share/elasticsearch/bin/elasticsearch-keystore |
44 |
| - add -f -x 'xpack.security.http.ssl.keystore.secure_password' |
45 |
| - changed_when: false |
46 |
| - no_log: true |
47 |
| - when: |
48 |
| - - elasticsearch_http_ssl_keystore_secure_password.stdout is undefined or elasticsearch_tls_key_passphrase != elasticsearch_http_ssl_keystore_secure_password.stdout |
49 |
| - - elasticsearch_http_security |
50 |
| - notify: |
51 |
| - - Restart Elasticsearch |
52 |
| - |
53 |
| -- name: Remove xpack.security.http.ssl.keystore.secure_password # noqa: risky-shell-pipe |
54 |
| - ansible.builtin.shell: > |
55 |
| - if test -n "$(ps -p $$ | grep bash)"; then set -o pipefail; fi; |
56 |
| - /usr/share/elasticsearch/bin/elasticsearch-keystore |
57 |
| - remove 'xpack.security.http.ssl.keystore.secure_password' |
58 |
| - changed_when: false |
59 |
| - no_log: true |
60 |
| - when: |
61 |
| - - "'xpack.security.http.ssl.keystore.secure_password' in elasticsearch_keystore.stdout_lines" |
62 |
| - - not elasticsearch_http_security |
63 |
| - notify: |
64 |
| - - Restart Elasticsearch |
65 |
| - |
66 |
| -- name: Get xpack.security.http.ssl.truststore.secure_password # noqa: risky-shell-pipe |
67 |
| - ansible.builtin.shell: > |
68 |
| - if test -n "$(ps -p $$ | grep bash)"; then set -o pipefail; fi; |
69 |
| - /usr/share/elasticsearch/bin/elasticsearch-keystore |
70 |
| - show 'xpack.security.http.ssl.truststore.secure_password' |
71 |
| - when: |
72 |
| - - "'xpack.security.http.ssl.truststore.secure_password' in elasticsearch_keystore.stdout_lines" |
73 |
| - - elasticsearch_http_security |
74 |
| - register: elasticsearch_http_ssl_truststore_secure_password |
75 |
| - ignore_errors: "{{ ansible_check_mode }}" |
76 |
| - no_log: true |
77 |
| - changed_when: false |
78 |
| - |
79 |
| -- name: Set xpack.security.http.ssl.truststore.secure_password # noqa: risky-shell-pipe |
80 |
| - ansible.builtin.shell: > |
81 |
| - if test -n "$(ps -p $$ | grep bash)"; then set -o pipefail; fi; |
82 |
| - echo "{{ elasticsearch_tls_key_passphrase }}" | |
83 |
| - /usr/share/elasticsearch/bin/elasticsearch-keystore |
84 |
| - add -f -x 'xpack.security.http.ssl.truststore.secure_password' |
85 |
| - changed_when: false |
86 |
| - no_log: true |
87 |
| - when: |
88 |
| - - elasticsearch_http_ssl_truststore_secure_password.stdout is undefined or elasticsearch_tls_key_passphrase != elasticsearch_http_ssl_truststore_secure_password.stdout |
89 |
| - - elasticsearch_http_security |
90 |
| - notify: |
91 |
| - - Restart Elasticsearch |
92 |
| - |
93 |
| -- name: Remove xpack.security.http.ssl.truststore.secure_password # noqa: risky-shell-pipe |
94 |
| - ansible.builtin.shell: > |
95 |
| - if test -n "$(ps -p $$ | grep bash)"; then set -o pipefail; fi; |
96 |
| - /usr/share/elasticsearch/bin/elasticsearch-keystore |
97 |
| - remove 'xpack.security.http.ssl.truststore.secure_password' |
98 |
| - changed_when: false |
99 |
| - no_log: true |
100 |
| - when: |
101 |
| - - "'xpack.security.http.ssl.truststore.secure_password' in elasticsearch_keystore.stdout_lines" |
102 |
| - - not elasticsearch_http_security |
103 |
| - notify: |
104 |
| - - Restart Elasticsearch |
105 |
| - |
106 |
| -- name: Get xpack.security.transport.ssl.keystore.secure_password # noqa: risky-shell-pipe |
107 |
| - ansible.builtin.shell: > |
108 |
| - if test -n "$(ps -p $$ | grep bash)"; then set -o pipefail; fi; |
109 |
| - /usr/share/elasticsearch/bin/elasticsearch-keystore |
110 |
| - show 'xpack.security.transport.ssl.keystore.secure_password' |
111 |
| - when: |
112 |
| - - "'xpack.security.transport.ssl.keystore.secure_password' in elasticsearch_keystore.stdout_lines" |
113 |
| - - elasticsearch_security |
114 |
| - register: elasticsearch_transport_ssl_keystore_secure_password |
115 |
| - ignore_errors: "{{ ansible_check_mode }}" |
116 |
| - no_log: true |
117 |
| - changed_when: false |
118 |
| - |
119 |
| -- name: Set xpack.security.transport.ssl.keystore.secure_password # noqa: risky-shell-pipe |
120 |
| - ansible.builtin.shell: > |
121 |
| - if test -n "$(ps -p $$ | grep bash)"; then set -o pipefail; fi; |
122 |
| - echo "{{ elasticsearch_tls_key_passphrase }}" | |
123 |
| - /usr/share/elasticsearch/bin/elasticsearch-keystore |
124 |
| - add -f -x 'xpack.security.transport.ssl.keystore.secure_password' |
125 |
| - changed_when: false |
126 |
| - no_log: true |
127 |
| - when: |
128 |
| - - elasticsearch_transport_ssl_keystore_secure_password.stdout is undefined or elasticsearch_tls_key_passphrase != elasticsearch_transport_ssl_keystore_secure_password.stdout |
129 |
| - - elasticsearch_security |
130 |
| - notify: |
131 |
| - - Restart Elasticsearch |
132 |
| - |
133 |
| -- name: Remove xpack.security.transport.ssl.keystore.secure_password # noqa: risky-shell-pipe |
134 |
| - ansible.builtin.shell: > |
135 |
| - if test -n "$(ps -p $$ | grep bash)"; then set -o pipefail; fi; |
136 |
| - /usr/share/elasticsearch/bin/elasticsearch-keystore |
137 |
| - remove 'xpack.security.transport.ssl.keystore.secure_password' |
138 |
| - changed_when: false |
139 |
| - no_log: true |
140 |
| - when: |
141 |
| - - "'xpack.security.transport.ssl.keystore.secure_password' in elasticsearch_keystore.stdout_lines" |
142 |
| - - not elasticsearch_security |
143 |
| - notify: |
144 |
| - - Restart Elasticsearch |
145 |
| - |
146 |
| -- name: Get xpack.security.transport.ssl.truststore.secure_password # noqa: risky-shell-pipe |
147 |
| - ansible.builtin.shell: > |
148 |
| - if test -n "$(ps -p $$ | grep bash)"; then set -o pipefail; fi; |
149 |
| - /usr/share/elasticsearch/bin/elasticsearch-keystore |
150 |
| - show 'xpack.security.transport.ssl.truststore.secure_password' |
151 |
| - when: |
152 |
| - - "'xpack.security.transport.ssl.truststore.secure_password' in elasticsearch_keystore.stdout_lines" |
153 |
| - - elasticsearch_security |
154 |
| - register: elasticsearch_transport_ssl_truststore_secure_password |
155 |
| - ignore_errors: "{{ ansible_check_mode }}" |
156 |
| - no_log: true |
157 |
| - changed_when: false |
158 |
| - |
159 |
| -- name: Set xpack.security.transport.ssl.truststore.secure_password # noqa: risky-shell-pipe |
160 |
| - ansible.builtin.shell: > |
161 |
| - if test -n "$(ps -p $$ | grep bash)"; then set -o pipefail; fi; |
162 |
| - echo "{{ elasticsearch_tls_key_passphrase }}" | |
163 |
| - /usr/share/elasticsearch/bin/elasticsearch-keystore |
164 |
| - add -f -x 'xpack.security.transport.ssl.truststore.secure_password' |
165 |
| - changed_when: false |
166 |
| - no_log: true |
167 |
| - when: |
168 |
| - - elasticsearch_transport_ssl_truststore_secure_password.stdout is undefined or elasticsearch_tls_key_passphrase != elasticsearch_transport_ssl_truststore_secure_password.stdout |
169 |
| - - elasticsearch_security |
170 |
| - notify: |
171 |
| - - Restart Elasticsearch |
172 |
| - |
173 |
| -- name: Remove xpack.security.transport.ssl.truststore.secure_password # noqa: risky-shell-pipe |
174 |
| - ansible.builtin.shell: > |
175 |
| - if test -n "$(ps -p $$ | grep bash)"; then set -o pipefail; fi; |
176 |
| - /usr/share/elasticsearch/bin/elasticsearch-keystore |
177 |
| - remove 'xpack.security.transport.ssl.truststore.secure_password' |
178 |
| - changed_when: false |
179 |
| - no_log: true |
180 |
| - when: |
181 |
| - - "'xpack.security.transport.ssl.truststore.secure_password' in elasticsearch_keystore.stdout_lines" |
182 |
| - - not elasticsearch_security |
183 |
| - notify: |
184 |
| - - Restart Elasticsearch |
| 11 | + register: elasticsearch_keystore_current_items |
| 12 | + |
| 13 | +- name: "Elasticsearch keystore: Include xpack.security.http.ssl variables" |
| 14 | + ansible.builtin.set_fact: |
| 15 | + # Combine data into the dictionary |
| 16 | + elasticsearch_keystore_vars: "{{ elasticsearch_keystore_vars | combine({'xpack.security.http.ssl.keystore.secure_password': elasticsearch_tls_key_passphrase, 'xpack.security.http.ssl.truststore.secure_password': elasticsearch_tls_key_passphrase}) }}" |
| 17 | + no_log: "{{ elasticstack_no_log }}" |
| 18 | + when: elasticsearch_http_security | default(false) | bool |
| 19 | + |
| 20 | +- name: "Elasticsearch keystore: Include xpack.security.transport.ssl variables" |
| 21 | + ansible.builtin.set_fact: |
| 22 | + # Combine data into the dictionary |
| 23 | + elasticsearch_keystore_vars: "{{ elasticsearch_keystore_vars | combine({'xpack.security.transport.ssl.keystore.secure_password': elasticsearch_tls_key_passphrase, 'xpack.security.transport.ssl.truststore.secure_password': elasticsearch_tls_key_passphrase}) }}" |
| 24 | + no_log: "{{ elasticstack_no_log }}" |
| 25 | + when: elasticsearch_security | default(false) | bool |
| 26 | + |
| 27 | +- name: Add/update elements to elasticsearch keystore |
| 28 | + ansible.builtin.include_tasks: |
| 29 | + elasticsearch-keystore-addupdate.yml |
| 30 | + no_log: "{{ elasticstack_no_log }}" |
| 31 | + loop: "{{ (elasticsearch_keystore_extra | dict2items) + (elasticsearch_keystore_vars | dict2items) }}" |
| 32 | + |
| 33 | +- name: Purge keys from elasticsearch keystore |
| 34 | + ansible.builtin.command: |
| 35 | + argv: |
| 36 | + - /usr/share/elasticsearch/bin/elasticsearch-keystore |
| 37 | + - remove |
| 38 | + - "{{ item | quote }}" |
| 39 | + changed_when: true |
| 40 | + loop: "{{ elasticsearch_keystore_current_items.stdout_lines }}" |
| 41 | + when: |
| 42 | + - elasticsearch_keystore_purge |
| 43 | + - item not in elasticsearch_keystore_vars |
| 44 | + - item not in elasticsearch_keystore_extra |
| 45 | + - item not in elasticsearch_keystore_builtin |
0 commit comments