|
| 1 | +--- |
| 2 | +- name: Flush Handlers to kickstart Elasticsearch to set up passwords |
| 3 | + ansible.builtin.meta: flush_handlers |
| 4 | + |
| 5 | +- name: Install expect for the interactive shells |
| 6 | + become: true |
| 7 | + ansible.builtin.apt: |
| 8 | + name: expect |
| 9 | + update_cache: true |
| 10 | + state: latest # noqa: package-latest |
| 11 | + |
| 12 | +- name: Set the elastic user password |
| 13 | + block: |
| 14 | + - name: Wait for Elasticsearch to be ready and check if current password is correct |
| 15 | + become: true |
| 16 | + ansible.builtin.uri: |
| 17 | + url: https://localhost:9200 |
| 18 | + return_content: true |
| 19 | + validate_certs: false |
| 20 | + url_username: "elastic" |
| 21 | + url_password: "{{ elastic_password }}" |
| 22 | + status_code: [401, 200] |
| 23 | + ca_path: /etc/elasticsearch/certs/elasticsearch.crt |
| 24 | + until: elastic_uri_output.status == 401 or elastic_uri_output.status == 200 |
| 25 | + retries: 10 |
| 26 | + delay: 5 |
| 27 | + register: elastic_uri_output |
| 28 | + |
| 29 | + - name: Reset Elastic user password |
| 30 | + become: true |
| 31 | + ansible.builtin.shell: | |
| 32 | + expect << EOF |
| 33 | + spawn /usr/share/elasticsearch/bin/elasticsearch-reset-password -u elastic -s -i |
| 34 | + expect -ex "Please confirm that you would like to continue \[y/N\]" |
| 35 | + send "y\r" |
| 36 | + expect -ex "Enter password for \[elastic\]:" |
| 37 | + send "{{ elastic_password }}\r" |
| 38 | + expect -ex "Re-enter password for \[elastic\]:" |
| 39 | + send "{{ elastic_password }}\r" |
| 40 | + expect eof |
| 41 | + EOF |
| 42 | + when: elastic_uri_output.status == 401 |
| 43 | + register: elastic_result |
| 44 | + changed_when: elastic_result.rc == 0 |
| 45 | + |
| 46 | +- name: Set the kibana_system user password |
| 47 | + block: |
| 48 | + - name: Wait for Elasticsearch to be ready and check if current password is correct |
| 49 | + become: true |
| 50 | + ansible.builtin.uri: |
| 51 | + url: https://localhost:9200 |
| 52 | + return_content: true |
| 53 | + validate_certs: false |
| 54 | + url_username: "kibana_system" |
| 55 | + url_password: "{{ kibana_system_password }}" |
| 56 | + status_code: [401, 200] |
| 57 | + ca_path: /etc/elasticsearch/certs/elasticsearch.crt |
| 58 | + until: elastic_uri_output.status == 401 or elastic_uri_output.status == 200 |
| 59 | + retries: 10 |
| 60 | + delay: 5 |
| 61 | + register: elastic_uri_output |
| 62 | + |
| 63 | + - name: Reset kibana_system user password |
| 64 | + become: true |
| 65 | + ansible.builtin.shell: | |
| 66 | + expect << EOF |
| 67 | + spawn /usr/share/elasticsearch/bin/elasticsearch-reset-password -u kibana_system -s -i |
| 68 | + expect -ex "Please confirm that you would like to continue \[y/N\]" |
| 69 | + send "y\r" |
| 70 | + expect -ex "Enter password for \[kibana_system\]:" |
| 71 | + send "{{ kibana_system_password }}\r" |
| 72 | + expect -ex "Re-enter password for \[kibana_system\]:" |
| 73 | + send "{{ kibana_system_password }}\r" |
| 74 | + expect eof |
| 75 | + EOF |
| 76 | + when: elastic_uri_output.status == 401 |
| 77 | + register: elastic_result |
| 78 | + changed_when: elastic_result.rc == 0 |
| 79 | + |
| 80 | +- name: Set the logstash_system user password |
| 81 | + block: |
| 82 | + - name: Wait for Elasticsearch to be ready and check if current password is correct |
| 83 | + become: true |
| 84 | + ansible.builtin.uri: |
| 85 | + url: https://localhost:9200 |
| 86 | + return_content: true |
| 87 | + validate_certs: false |
| 88 | + url_username: "logstash_system" |
| 89 | + url_password: "{{ logstash_system_password }}" |
| 90 | + status_code: [401, 200] |
| 91 | + ca_path: /etc/elasticsearch/certs/elasticsearch.crt |
| 92 | + until: elastic_uri_output.status == 401 or elastic_uri_output.status == 200 |
| 93 | + retries: 10 |
| 94 | + delay: 5 |
| 95 | + register: elastic_uri_output |
| 96 | + |
| 97 | + - name: Reset logstash_system user password |
| 98 | + become: true |
| 99 | + ansible.builtin.shell: | |
| 100 | + expect << EOF |
| 101 | + spawn /usr/share/elasticsearch/bin/elasticsearch-reset-password -u logstash_system -s -i |
| 102 | + expect -ex "Please confirm that you would like to continue \[y/N\]" |
| 103 | + send "y\r" |
| 104 | + expect -ex "Enter password for \[logstash_system\]:" |
| 105 | + send "{{ logstash_system_password }}\r" |
| 106 | + expect -ex "Re-enter password for \[logstash_system\]:" |
| 107 | + send "{{ logstash_system_password }}\r" |
| 108 | + expect eof |
| 109 | + EOF |
| 110 | + when: elastic_uri_output.status == 401 |
| 111 | + register: elastic_result |
| 112 | + changed_when: elastic_result.rc == 0 |
0 commit comments