2024-05-26 14:55:39 +00:00
|
|
|
---
|
|
|
|
- name: Reset {{ patroni_superuser_username }} password after restore
|
|
|
|
block:
|
|
|
|
- name: Wait for Patroni leader
|
|
|
|
vars:
|
|
|
|
_query: 'json.members[].role'
|
|
|
|
ansible.builtin.uri:
|
2024-07-24 09:22:08 +00:00
|
|
|
url: "{{ 'https://' if patroni_ssl else 'http://' }}{{ patroni_restapi_listen_address }}:{{ patroni_restapi_listen_port }}/cluster"
|
2024-05-26 14:55:39 +00:00
|
|
|
method: GET
|
|
|
|
body_format: json
|
|
|
|
status_code:
|
|
|
|
- 200
|
|
|
|
- 503
|
|
|
|
register: patroni_role
|
|
|
|
until: patroni_role | json_query(_query) | regex_findall('leader') | count > 0
|
|
|
|
retries: 100
|
|
|
|
delay: 10
|
|
|
|
|
|
|
|
- name: Get Patroni nodes roles
|
|
|
|
ansible.builtin.uri:
|
2024-07-24 09:22:08 +00:00
|
|
|
url: "{{ 'https://' if patroni_ssl else 'http://' }}{{ patroni_restapi_listen_address }}:{{ patroni_restapi_listen_port }}"
|
2024-05-26 14:55:39 +00:00
|
|
|
method: GET
|
|
|
|
body_format: json
|
|
|
|
status_code:
|
|
|
|
- 200
|
|
|
|
- 503
|
|
|
|
register: patroni_role
|
|
|
|
|
|
|
|
- name: Set fact about roles
|
|
|
|
set_fact:
|
|
|
|
role: "{{ patroni_role.json.role }}"
|
|
|
|
|
|
|
|
- name: Reset {{ patroni_superuser_username }} password after restore
|
2024-07-24 09:22:08 +00:00
|
|
|
become_user: "{{ patroni_user }}"
|
2024-05-26 14:55:39 +00:00
|
|
|
community.postgresql.postgresql_query:
|
|
|
|
db: "{{ patroni_superuser_db }}"
|
|
|
|
query: ALTER USER {{ patroni_superuser_username }} with password '{{ patroni_superuser_password }}';
|
|
|
|
when:
|
|
|
|
- "hostvars[inventory_hostname]['role'] == 'master'"
|
|
|
|
rescue:
|
2024-07-24 09:22:08 +00:00
|
|
|
- include_tasks: reset-password-after-restore.yaml
|