From b13a4cb9dc3399eb5460ac8071fe98996f907d87 Mon Sep 17 00:00:00 2001 From: liza-mae Date: Thu, 30 Aug 2018 12:44:16 -0600 Subject: [PATCH] Make xpack elasticsearch role idempotent (#31) --- .../xpack_elasticsearch_set_passwords.yml | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/ansible/roles/xpack_elasticsearch/tasks/linux/xpack_elasticsearch_set_passwords.yml b/ansible/roles/xpack_elasticsearch/tasks/linux/xpack_elasticsearch_set_passwords.yml index 708a19302a2d93..09d9228e5c48ec 100644 --- a/ansible/roles/xpack_elasticsearch/tasks/linux/xpack_elasticsearch_set_passwords.yml +++ b/ansible/roles/xpack_elasticsearch/tasks/linux/xpack_elasticsearch_set_passwords.yml @@ -6,6 +6,21 @@ --- +- name: Check if password is set + block: + - name: Elasticsearch HTTPS GET ?pretty + uri: + url: "https://{{ current_host_ip }}:{{ elasticsearch_port }}/?pretty" + method: GET + user: "{{ elasticsearch_username }}" + password: "{{ elasticsearch_password }}" + validate_certs: no + return_content: yes + status_code: 200, 401 + register: elastic_user_auth + - debug: + msg: '{{ elastic_user_auth }}' + - name: Check if setup passwords executable exists stat: path: '{{ elasticsearch_setup_passwords_exe }}' @@ -16,7 +31,8 @@ echo 'y' | {{ elasticsearch_setup_passwords_exe }} auto register: initial_passwords when: file_setup_passwords.stat.exists is defined and file_setup_passwords.stat.exists and - file_setup_passwords.stat.executable is defined and file_setup_passwords.stat.executable + file_setup_passwords.stat.executable is defined and file_setup_passwords.stat.executable and + elastic_user_auth.status == 401 - debug: msg: '{{ initial_passwords }}'