Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions roles/elasticsearch/tasks/elasticsearch-keystore.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
- bootstrap.password
stdin: "{{ elasticsearch_bootstrap_pw }}"
when: "'bootstrap.password' not in elasticsearch_keystore.stdout_lines"
changed_when: false
changed_when: true
no_log: true
notify:
- Restart Elasticsearch
Expand Down Expand Up @@ -48,7 +48,7 @@
- -x
- xpack.security.http.ssl.keystore.secure_password
stdin: "{{ elasticsearch_tls_key_passphrase }}"
changed_when: false
changed_when: true
no_log: true
when:
- elasticsearch_http_ssl_keystore_secure_password.stdout is undefined or elasticsearch_tls_key_passphrase != elasticsearch_http_ssl_keystore_secure_password.stdout
Expand All @@ -62,7 +62,7 @@
- /usr/share/elasticsearch/bin/elasticsearch-keystore
- remove
- xpack.security.http.ssl.keystore.secure_password
changed_when: false
changed_when: true
no_log: true
when:
- "'xpack.security.http.ssl.keystore.secure_password' in elasticsearch_keystore.stdout_lines"
Expand Down Expand Up @@ -93,7 +93,7 @@
- -x
- xpack.security.http.ssl.truststore.secure_password
stdin: "{{ elasticsearch_tls_key_passphrase }}"
changed_when: false
changed_when: true
no_log: true
when:
- elasticsearch_http_ssl_truststore_secure_password.stdout is undefined or elasticsearch_tls_key_passphrase != elasticsearch_http_ssl_truststore_secure_password.stdout
Expand All @@ -107,7 +107,7 @@
- /usr/share/elasticsearch/bin/elasticsearch-keystore
- remove
- xpack.security.http.ssl.truststore.secure_password
changed_when: false
changed_when: true
no_log: true
when:
- "'xpack.security.http.ssl.truststore.secure_password' in elasticsearch_keystore.stdout_lines"
Expand Down Expand Up @@ -138,7 +138,7 @@
- -x
- xpack.security.transport.ssl.keystore.secure_password
stdin: "{{ elasticsearch_tls_key_passphrase }}"
changed_when: false
changed_when: true
no_log: true
when:
- elasticsearch_transport_ssl_keystore_secure_password.stdout is undefined or elasticsearch_tls_key_passphrase != elasticsearch_transport_ssl_keystore_secure_password.stdout
Expand All @@ -152,7 +152,7 @@
- /usr/share/elasticsearch/bin/elasticsearch-keystore
- remove
- xpack.security.transport.ssl.keystore.secure_password
changed_when: false
changed_when: true
no_log: true
when:
- "'xpack.security.transport.ssl.keystore.secure_password' in elasticsearch_keystore.stdout_lines"
Expand Down Expand Up @@ -183,7 +183,7 @@
- -x
- xpack.security.transport.ssl.truststore.secure_password
stdin: "{{ elasticsearch_tls_key_passphrase }}"
changed_when: false
changed_when: true
no_log: true
when:
- elasticsearch_transport_ssl_truststore_secure_password.stdout is undefined or elasticsearch_tls_key_passphrase != elasticsearch_transport_ssl_truststore_secure_password.stdout
Expand All @@ -197,7 +197,7 @@
- /usr/share/elasticsearch/bin/elasticsearch-keystore
- remove
- xpack.security.transport.ssl.truststore.secure_password
changed_when: false
changed_when: true
no_log: true
when:
- "'xpack.security.transport.ssl.truststore.secure_password' in elasticsearch_keystore.stdout_lines"
Expand Down
14 changes: 7 additions & 7 deletions roles/elasticsearch/tasks/elasticsearch-rolling-upgrade.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
body: '{ "persistent": { "cluster.routing.allocation.enable": null }}'
body_format: json
user: elastic
password: "{{ elasticstack_password.stdout }}"
password: "{{ __elasticstack_password }}"
validate_certs: no
register: response
# next line is boolean not string, so no quotes around true
Expand All @@ -96,7 +96,7 @@
url: "{{ elasticsearch_http_protocol }}://{{ elasticsearch_api_host }}:{{ elasticstack_elasticsearch_http_port }}/_cluster/health"
method: GET
user: elastic
password: "{{ elasticstack_password.stdout }}"
password: "{{ __elasticstack_password }}"
validate_certs: no
register: response
until: "response.json.status == 'green'"
Expand All @@ -111,15 +111,15 @@
body: '{ "persistent": { "cluster.routing.allocation.enable": "none" }}'
body_format: json
user: elastic
password: "{{ elasticstack_password.stdout }}"
password: "{{ __elasticstack_password }}"
validate_certs: no

- name: Stop non essential indexing to speed up shard recovery
ansible.builtin.uri:
url: "{{ elasticsearch_http_protocol }}://{{ elasticsearch_api_host }}:{{ elasticstack_elasticsearch_http_port }}/_flush"
method: POST
user: elastic
password: "{{ elasticstack_password.stdout }}"
password: "{{ __elasticstack_password }}"
validate_certs: no
failed_when: false

Expand Down Expand Up @@ -176,7 +176,7 @@
if test -n "$(ps -p $$ | grep bash)"; then set -o pipefail; fi;
curl
-k
-u elastic:{{ elasticstack_password.stdout }}
-u elastic:{{ __elasticstack_password }}
-s
-m 2
'{{ elasticsearch_http_protocol }}://{{ elasticsearch_api_host }}:{{ elasticstack_elasticsearch_http_port }}/_cat/nodes?h=name'
Expand All @@ -196,7 +196,7 @@
body: '{ "persistent": { "cluster.routing.allocation.enable": null }}'
body_format: json
user: elastic
password: "{{ elasticstack_password.stdout }}"
password: "{{ __elasticstack_password }}"
validate_certs: no
register: response
# next line is boolean not string, so no quotes around true
Expand All @@ -210,7 +210,7 @@
url: "{{ elasticsearch_http_protocol }}://{{ elasticsearch_api_host }}:{{ elasticstack_elasticsearch_http_port }}/_cluster/health"
method: GET
user: elastic
password: "{{ elasticstack_password.stdout }}"
password: "{{ __elasticstack_password }}"
validate_certs: no
register: response
until: "response.json.status == 'yellow' or response.json.status == 'green'"
Expand Down
8 changes: 7 additions & 1 deletion roles/elasticsearch/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@
- "hostvars[item].inventory_hostname == inventory_hostname"
- elasticstack_version is defined
- ansible_facts.packages['elasticsearch'][0].version is defined
- elasticstack_password.stdout is defined
- __elasticstack_password is defined
- elasticstack_version is version( ansible_facts.packages['elasticsearch'][0].version, '>')

- name: Install Elasticsearch - rpm - full stack
Expand All @@ -147,6 +147,8 @@
when:
- ansible_os_family == "RedHat"
- elasticstack_full_stack | bool
# fresh install only, an upgrade goes through elasticsearch-rolling-upgrade.yml
- "'elasticsearch' not in ansible_facts.packages"

- name: Install Elasticsearch - rpm - standalone
ansible.builtin.package:
Expand All @@ -155,13 +157,17 @@
when:
- ansible_os_family == "RedHat"
- not elasticstack_full_stack | bool
# fresh install only, an upgrade goes through elasticsearch-rolling-upgrade.yml
- "'elasticsearch' not in ansible_facts.packages"

- name: Install Elasticsearch - deb
ansible.builtin.package:
name: "{{ elasticsearch_package }}"
state: present
when:
- ansible_os_family == "Debian"
# fresh install only, an upgrade goes through elasticsearch-rolling-upgrade.yml
- "'elasticsearch' not in ansible_facts.packages"

- name: Configure Elasticsearch
ansible.builtin.template:
Expand Down
1 change: 0 additions & 1 deletion roles/elasticsearch/templates/elasticsearch.yml.j2
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# test
{{ ansible_managed | comment }}

node.name: "{{ elasticsearch_nodename }}"
Expand Down
9 changes: 8 additions & 1 deletion roles/elasticstack/tasks/elasticstack-passwords.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,22 @@
ansible.builtin.stat:
path: "{{ elasticstack_initial_passwords }}"
delegate_to: "{{ elasticstack_ca_host | default(omit, true) }}"
run_once: true
register: elasticsearch_passwords_file

- name: Fetch Elastic password # noqa: risky-shell-pipe
ansible.builtin.shell: >
if test -n "$(ps -p $$ | grep bash)"; then set -o pipefail; fi;
grep "PASSWORD elastic" {{ elasticstack_initial_passwords }} |
awk {' print $4 '}
register: elasticstack_password
register: __elasticstack_password_fetch
run_once: true
changed_when: false
no_log: "{{ elasticstack_no_log }}"
delegate_to: "{{ elasticstack_ca_host | default(omit, true) }}"
when: elasticsearch_passwords_file.stat.exists | bool

- name: Persist the elastic password as a fact for all roles
ansible.builtin.set_fact:
__elasticstack_password: "{{ __elasticstack_password_fetch.stdout }}"
when: __elasticstack_password_fetch.stdout is defined
1 change: 0 additions & 1 deletion roles/elasticstack/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

- name: Set versions for components
ansible.builtin.import_tasks: elasticstack-versions.yml
when: elasticstack_full_stack | bool

- name: Fetch passwords if passwords are initialized
ansible.builtin.import_tasks: elasticstack-passwords.yml
Expand Down