patroni/tasks/dynamic_config.yaml

59 lines
2.1 KiB
YAML
Raw Normal View History

2023-02-07 23:39:20 +00:00
---
2023-07-03 21:00:54 +00:00
- name: Merge Patroni dynamic parameters for backup
set_fact:
patroni_postgresql_dynamic_parameters: "{{ patroni_postgresql_dynamic_parameters | combine(patroni_postgresql_backup_parameters, recursive=true) }}"
2023-02-07 23:39:20 +00:00
- name: Propagate Patroni dynamic config
copy:
content: "{{ patroni_postgresql_dynamic_parameters | to_nice_json }}"
dest: "/etc/patroni/dynamic.json"
owner: "postgres"
group: "postgres"
mode: 0644
register: patroni_dynamic_config_file
- name: Dynamic configuration parameters for Patroni
when: patroni_dynamic_config_file.changed
block:
2023-07-21 14:13:51 +00:00
- name: Wait for Patroni leader
vars:
_query: 'json.members[].role'
ansible.builtin.uri:
url: "{{ 'https://' if patroni_ssl else 'http://' }}{{ hostvars[inventory_hostname]['ansible_default_ipv4']['address'] }}:{{ patroni_restapi_listen_port }}/cluster"
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
2023-02-07 23:39:20 +00:00
ansible.builtin.uri:
url: "{{ 'https://' if patroni_ssl else 'http://' }}{{ hostvars[inventory_hostname]['ansible_default_ipv4']['address'] }}:{{ patroni_restapi_listen_port }}"
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: Apply dynamic configuration parameters for Patroni
ansible.builtin.uri:
url: "{{ 'https://' if patroni_ssl else 'http://' }}{{ hostvars[inventory_hostname]['ansible_default_ipv4']['address'] }}:{{ patroni_restapi_listen_port }}/config"
user: "{{ patroni_restapi_username }}"
password: "{{ patroni_restapi_password }}"
method: PATCH
body: "{{ patroni_postgresql_dynamic_parameters | to_nice_json }}"
force_basic_auth: yes
when:
- "hostvars[inventory_hostname]['role'] == 'master'"
2023-07-21 14:13:51 +00:00
rescue:
- include_tasks: dynamic_config.yaml