patroni/tasks/dynamic_config.yaml
2023-02-08 02:39:20 +03:00

39 lines
1.3 KiB
YAML

---
- 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:
- name: Find Patroni master
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'"