add restore support

This commit is contained in:
ace
2023-07-21 17:13:51 +03:00
parent 11d311a96a
commit 4759d93a91
12 changed files with 77 additions and 41 deletions

View File

@ -3,10 +3,6 @@
set_fact:
patroni_postgresql_parameters_combined: "{{ patroni_postgresql_default_parameters | combine(patroni_postgresql_parameters|default({}), recursive=true) }}"
- name: Merge backup options for PostgreSQL part of Patroni config
set_fact:
patroni_postgresql_parameters_combined: "{{ patroni_postgresql_parameters_combined | combine(patroni_postgresql_backup_parameters['postgresql']['parameters']|default({}), recursive=true) }}"
- name: Template Patroni default config
set_fact:
patroni_default_config: "{{ lookup('template', 'patroni.yaml.j2') | from_yaml }}"
@ -45,3 +41,11 @@
register: patroni_config_file
when: not patroni_config_file_exists_result.stat.exists
notify: Restart Patroni
- name: Propagate Patroni restore script
template:
src: "restore.sh.j2"
dest: "{{ patroni_restore_script }}"
owner: "postgres"
group: "postgres"
mode: 0755

View File

@ -15,7 +15,22 @@
- name: Dynamic configuration parameters for Patroni
when: patroni_dynamic_config_file.changed
block:
- name: Find Patroni master
- 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
ansible.builtin.uri:
url: "{{ 'https://' if patroni_ssl else 'http://' }}{{ hostvars[inventory_hostname]['ansible_default_ipv4']['address'] }}:{{ patroni_restapi_listen_port }}"
method: GET
@ -39,4 +54,5 @@
force_basic_auth: yes
when:
- "hostvars[inventory_hostname]['role'] == 'master'"
rescue:
- include_tasks: dynamic_config.yaml

View File

@ -70,9 +70,10 @@
register: patroni_enable_and_start
tags: patroni, patroni_start
- name: "Dynamic Patroni configuration"
include_tasks: dynamic_config.yaml
#when:
# - patroni_postgresql_dynamic_parameters
tags: patroni_dynamic_configure
#- name: Patroni cluster reconfiguration after restore from backup
# include_tasks: restore.yaml
# when: patroni_wal_g_restore_from_backup
- name: Dynamic Patroni configuration
include_tasks: dynamic_config.yaml
tags: patroni_dynamic_configure

7
tasks/restore.yaml Normal file
View File

@ -0,0 +1,7 @@
---
- name: Copy walg-backup to walg-restore after restore
copy:
src: "{{ patroni_postgresql_home_dir ~ '/' ~ patroni_wal_g_backup_config_name }}"
dest: "{{ patroni_postgresql_home_dir ~ '/' ~ patroni_wal_g_restore_config_name }}"
remote_src: true
when: patroni_wal_g_backup