fix backup/restore and update vars for patroni rest

This commit is contained in:
ace 2024-07-24 12:22:08 +03:00
parent 7bf4ad8d17
commit c8d358bbe3
Signed by: ace
GPG Key ID: 2C08973DD37A76FD
6 changed files with 19 additions and 16 deletions

View File

@ -48,6 +48,9 @@ patroni_dcs_type: "consul"
## WAL-G backup and restore options ## WAL-G backup and restore options
patroni_wal_g_install: false patroni_wal_g_install: false
patroni_wal_g_backup_enable: false
patroni_wal_g_backup_permanent_enable: false
patroni_wal_g_backup_retention_enable: false
patroni_wal_g_restore_from_backup: false patroni_wal_g_restore_from_backup: false
patroni_wal_g_pitr: "" patroni_wal_g_pitr: ""
patroni_wal_g_restore_backup_name: "LATEST" patroni_wal_g_restore_backup_name: "LATEST"
@ -79,7 +82,8 @@ patroni_synchronous_mode: false # or 'true' for enable synchronous database rep
patroni_synchronous_mode_strict: false # if 'true' then block all client writes to the master, when a synchronous replica is not available patroni_synchronous_mode_strict: false # if 'true' then block all client writes to the master, when a synchronous replica is not available
patroni_synchronous_node_count: 2 # number of synchronous standby databases patroni_synchronous_node_count: 2 # number of synchronous standby databases
patroni_postgresql_port: "5432" patroni_postgresql_listen_address: "0.0.0.0"
patroni_postgresql_listen_port: "5432"
patroni_postgresql_encoding: "UTF8" # for bootstrap only (initdb) patroni_postgresql_encoding: "UTF8" # for bootstrap only (initdb)
patroni_postgresql_locale: "en_US.UTF-8" # for bootstrap only (initdb) patroni_postgresql_locale: "en_US.UTF-8" # for bootstrap only (initdb)
patroni_postgresql_data_checksums: true # for bootstrap only (initdb) patroni_postgresql_data_checksums: true # for bootstrap only (initdb)
@ -115,8 +119,8 @@ patroni_postgresql_dynamic_parameters: {}
patroni_postgresql_backup_parameters: patroni_postgresql_backup_parameters:
postgresql: postgresql:
parameters: parameters:
archive_command: "{{ patroni_postgresql_archive_command if patroni_wal_g_backup_enable else 'cd .' }}" archive_command: "{{ patroni_postgresql_archive_command if patroni_wal_g_install else 'cd .' }}"
restore_command: "{{ patroni_postgresql_restore_command if patroni_wal_g_backup_enable else 'cd .' }}" restore_command: "{{ patroni_postgresql_restore_command if (patroni_wal_g_install or patroni_wal_g_restore_from_backup) else 'cd .' }}"
# postgresql parameters to bootstrap dcs (are parameters for example) # postgresql parameters to bootstrap dcs (are parameters for example)
patroni_postgresql_max_connections: "1000" patroni_postgresql_max_connections: "1000"

View File

@ -36,7 +36,6 @@
patroni_create_replica_methods: "{{ patroni_create_replica_methods + [ 'wal_g' ] }}" patroni_create_replica_methods: "{{ patroni_create_replica_methods + [ 'wal_g' ] }}"
when: when:
- patroni_wal_g_install - patroni_wal_g_install
- patroni_wal_g_backup_enable
- name: Propagate Patroni config - name: Propagate Patroni config
copy: copy:

View File

@ -19,7 +19,7 @@
vars: vars:
_query: 'json.members[].role' _query: 'json.members[].role'
ansible.builtin.uri: ansible.builtin.uri:
url: "{{ 'https://' if patroni_ssl else 'http://' }}{{ hostvars[inventory_hostname]['ansible_default_ipv4']['address'] }}:{{ patroni_restapi_listen_port }}/cluster" url: "{{ 'https://' if patroni_ssl else 'http://' }}{{ patroni_restapi_listen_address }}:{{ patroni_restapi_listen_port }}/cluster"
method: GET method: GET
body_format: json body_format: json
status_code: status_code:
@ -32,7 +32,7 @@
- name: Get Patroni nodes roles - name: Get Patroni nodes roles
ansible.builtin.uri: ansible.builtin.uri:
url: "{{ 'https://' if patroni_ssl else 'http://' }}{{ hostvars[inventory_hostname]['ansible_default_ipv4']['address'] }}:{{ patroni_restapi_listen_port }}" url: "{{ 'https://' if patroni_ssl else 'http://' }}{{ patroni_restapi_listen_address }}:{{ patroni_restapi_listen_port }}"
method: GET method: GET
body_format: json body_format: json
status_code: status_code:
@ -46,7 +46,7 @@
- name: Apply dynamic configuration parameters for Patroni - name: Apply dynamic configuration parameters for Patroni
ansible.builtin.uri: ansible.builtin.uri:
url: "{{ 'https://' if patroni_ssl else 'http://' }}{{ hostvars[inventory_hostname]['ansible_default_ipv4']['address'] }}:{{ patroni_restapi_listen_port }}/config" url: "{{ 'https://' if patroni_ssl else 'http://' }}{{ patroni_restapi_listen_address }}:{{ patroni_restapi_listen_port }}/config"
user: "{{ patroni_restapi_username }}" user: "{{ patroni_restapi_username }}"
password: "{{ patroni_restapi_password }}" password: "{{ patroni_restapi_password }}"
method: PATCH method: PATCH

View File

@ -5,7 +5,7 @@
vars: vars:
_query: 'json.members[].role' _query: 'json.members[].role'
ansible.builtin.uri: ansible.builtin.uri:
url: "{{ 'https://' if patroni_ssl else 'http://' }}{{ hostvars[inventory_hostname]['ansible_default_ipv4']['address'] }}:{{ patroni_restapi_listen_port }}/cluster" url: "{{ 'https://' if patroni_ssl else 'http://' }}{{ patroni_restapi_listen_address }}:{{ patroni_restapi_listen_port }}/cluster"
method: GET method: GET
body_format: json body_format: json
status_code: status_code:
@ -18,7 +18,7 @@
- name: Get Patroni nodes roles - name: Get Patroni nodes roles
ansible.builtin.uri: ansible.builtin.uri:
url: "{{ 'https://' if patroni_ssl else 'http://' }}{{ hostvars[inventory_hostname]['ansible_default_ipv4']['address'] }}:{{ patroni_restapi_listen_port }}" url: "{{ 'https://' if patroni_ssl else 'http://' }}{{ patroni_restapi_listen_address }}:{{ patroni_restapi_listen_port }}"
method: GET method: GET
body_format: json body_format: json
status_code: status_code:
@ -31,11 +31,11 @@
role: "{{ patroni_role.json.role }}" role: "{{ patroni_role.json.role }}"
- name: Reset {{ patroni_superuser_username }} password after restore - name: Reset {{ patroni_superuser_username }} password after restore
become_user: "{{ postgresql_user }}" become_user: "{{ patroni_user }}"
community.postgresql.postgresql_query: community.postgresql.postgresql_query:
db: "{{ patroni_superuser_db }}" db: "{{ patroni_superuser_db }}"
query: ALTER USER {{ patroni_superuser_username }} with password '{{ patroni_superuser_password }}'; query: ALTER USER {{ patroni_superuser_username }} with password '{{ patroni_superuser_password }}';
when: when:
- "hostvars[inventory_hostname]['role'] == 'master'" - "hostvars[inventory_hostname]['role'] == 'master'"
rescue: rescue:
- include_tasks: /reset-password-after-restore.yaml - include_tasks: reset-password-after-restore.yaml

View File

@ -5,7 +5,7 @@
vars: vars:
_query: 'json.members[].role' _query: 'json.members[].role'
ansible.builtin.uri: ansible.builtin.uri:
url: "{{ 'https://' if patroni_ssl else 'http://' }}{{ hostvars[inventory_hostname]['ansible_default_ipv4']['address'] }}:{{ patroni_restapi_listen_port }}/cluster" url: "{{ 'https://' if patroni_ssl else 'http://' }}{{ patroni_restapi_listen_address }}:{{ patroni_restapi_listen_port }}/cluster"
method: GET method: GET
body_format: json body_format: json
status_code: status_code:
@ -18,7 +18,7 @@
- name: Get Patroni nodes roles - name: Get Patroni nodes roles
ansible.builtin.uri: ansible.builtin.uri:
url: "{{ 'https://' if patroni_ssl else 'http://' }}{{ hostvars[inventory_hostname]['ansible_default_ipv4']['address'] }}:{{ patroni_restapi_listen_port }}" url: "{{ 'https://' if patroni_ssl else 'http://' }}{{ patroni_restapi_listen_address }}:{{ patroni_restapi_listen_port }}"
method: GET method: GET
body_format: json body_format: json
status_code: status_code:
@ -33,7 +33,7 @@
- name: Restart if pending restart - name: Restart if pending restart
throttle: 1 throttle: 1
ansible.builtin.uri: ansible.builtin.uri:
url: "{{ 'https://' if patroni_ssl else 'http://' }}{{ hostvars[inventory_hostname]['ansible_default_ipv4']['address'] }}:{{ patroni_restapi_listen_port }}/restart" url: "{{ 'https://' if patroni_ssl else 'http://' }}{{ patroni_restapi_listen_address }}:{{ patroni_restapi_listen_port }}/restart"
user: "{{ patroni_restapi_username }}" user: "{{ patroni_restapi_username }}"
password: "{{ patroni_restapi_password }}" password: "{{ patroni_restapi_password }}"
method: POST method: POST

View File

@ -125,8 +125,8 @@ bootstrap:
- host replication replicator 0.0.0.0/0 {{ patroni_postgresql_password_encryption_algorithm }} - host replication replicator 0.0.0.0/0 {{ patroni_postgresql_password_encryption_algorithm }}
postgresql: postgresql:
listen: 0.0.0.0:{{ patroni_postgresql_port }} listen: {{ patroni_postgresql_listen_address }}:{{ patroni_postgresql_listen_port }}
connect_address: {{ hostvars[inventory_hostname]['ansible_host'] }}:{{ patroni_postgresql_port }} connect_address: {{ hostvars[inventory_hostname]['ansible_host'] }}:{{ patroni_postgresql_listen_port }}
use_unix_socket: true use_unix_socket: true
data_dir: {{ patroni_postgresql_home_dir }}/{{ patroni_postgresql_major_version }}/{{ patroni_postgresql_cluster_name }} data_dir: {{ patroni_postgresql_home_dir }}/{{ patroni_postgresql_major_version }}/{{ patroni_postgresql_cluster_name }}
bin_dir: {{ patroni_postgresql_bin_dir }} bin_dir: {{ patroni_postgresql_bin_dir }}