From c8d358bbe3e2def67de2cdf381e864508e797bbc Mon Sep 17 00:00:00 2001 From: ace Date: Wed, 24 Jul 2024 12:22:08 +0300 Subject: [PATCH] fix backup/restore and update vars for patroni rest --- defaults/main.yaml | 10 +++++++--- tasks/config.yaml | 1 - tasks/dynamic_config.yaml | 6 +++--- tasks/reset-password-after-restore.yaml | 8 ++++---- tasks/restart_pending.yaml | 6 +++--- templates/patroni.yaml.j2 | 4 ++-- 6 files changed, 19 insertions(+), 16 deletions(-) diff --git a/defaults/main.yaml b/defaults/main.yaml index de44f2a..3b0075f 100644 --- a/defaults/main.yaml +++ b/defaults/main.yaml @@ -48,6 +48,9 @@ patroni_dcs_type: "consul" ## WAL-G backup and restore options 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_pitr: "" 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_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_locale: "en_US.UTF-8" # 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: postgresql: parameters: - archive_command: "{{ patroni_postgresql_archive_command if patroni_wal_g_backup_enable else 'cd .' }}" - restore_command: "{{ patroni_postgresql_restore_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_install or patroni_wal_g_restore_from_backup) else 'cd .' }}" # postgresql parameters to bootstrap dcs (are parameters for example) patroni_postgresql_max_connections: "1000" diff --git a/tasks/config.yaml b/tasks/config.yaml index b3ba219..28601a5 100644 --- a/tasks/config.yaml +++ b/tasks/config.yaml @@ -36,7 +36,6 @@ patroni_create_replica_methods: "{{ patroni_create_replica_methods + [ 'wal_g' ] }}" when: - patroni_wal_g_install - - patroni_wal_g_backup_enable - name: Propagate Patroni config copy: diff --git a/tasks/dynamic_config.yaml b/tasks/dynamic_config.yaml index 81b35a4..ac8fcf5 100644 --- a/tasks/dynamic_config.yaml +++ b/tasks/dynamic_config.yaml @@ -19,7 +19,7 @@ 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" + url: "{{ 'https://' if patroni_ssl else 'http://' }}{{ patroni_restapi_listen_address }}:{{ patroni_restapi_listen_port }}/cluster" method: GET body_format: json status_code: @@ -32,7 +32,7 @@ - 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 }}" + url: "{{ 'https://' if patroni_ssl else 'http://' }}{{ patroni_restapi_listen_address }}:{{ patroni_restapi_listen_port }}" method: GET body_format: json status_code: @@ -46,7 +46,7 @@ - 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" + url: "{{ 'https://' if patroni_ssl else 'http://' }}{{ patroni_restapi_listen_address }}:{{ patroni_restapi_listen_port }}/config" user: "{{ patroni_restapi_username }}" password: "{{ patroni_restapi_password }}" method: PATCH diff --git a/tasks/reset-password-after-restore.yaml b/tasks/reset-password-after-restore.yaml index 6e131b5..fb6ef85 100644 --- a/tasks/reset-password-after-restore.yaml +++ b/tasks/reset-password-after-restore.yaml @@ -5,7 +5,7 @@ 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" + url: "{{ 'https://' if patroni_ssl else 'http://' }}{{ patroni_restapi_listen_address }}:{{ patroni_restapi_listen_port }}/cluster" method: GET body_format: json status_code: @@ -18,7 +18,7 @@ - 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 }}" + url: "{{ 'https://' if patroni_ssl else 'http://' }}{{ patroni_restapi_listen_address }}:{{ patroni_restapi_listen_port }}" method: GET body_format: json status_code: @@ -31,11 +31,11 @@ role: "{{ patroni_role.json.role }}" - name: Reset {{ patroni_superuser_username }} password after restore - become_user: "{{ postgresql_user }}" + become_user: "{{ patroni_user }}" 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: - - include_tasks: /reset-password-after-restore.yaml + - include_tasks: reset-password-after-restore.yaml diff --git a/tasks/restart_pending.yaml b/tasks/restart_pending.yaml index ece7d50..0dfbc80 100644 --- a/tasks/restart_pending.yaml +++ b/tasks/restart_pending.yaml @@ -5,7 +5,7 @@ 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" + url: "{{ 'https://' if patroni_ssl else 'http://' }}{{ patroni_restapi_listen_address }}:{{ patroni_restapi_listen_port }}/cluster" method: GET body_format: json status_code: @@ -18,7 +18,7 @@ - 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 }}" + url: "{{ 'https://' if patroni_ssl else 'http://' }}{{ patroni_restapi_listen_address }}:{{ patroni_restapi_listen_port }}" method: GET body_format: json status_code: @@ -33,7 +33,7 @@ - name: Restart if pending restart throttle: 1 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 }}" password: "{{ patroni_restapi_password }}" method: POST diff --git a/templates/patroni.yaml.j2 b/templates/patroni.yaml.j2 index 93ee934..b0de8e7 100644 --- a/templates/patroni.yaml.j2 +++ b/templates/patroni.yaml.j2 @@ -125,8 +125,8 @@ bootstrap: - host replication replicator 0.0.0.0/0 {{ patroni_postgresql_password_encryption_algorithm }} postgresql: - listen: 0.0.0.0:{{ patroni_postgresql_port }} - connect_address: {{ hostvars[inventory_hostname]['ansible_host'] }}:{{ patroni_postgresql_port }} + listen: {{ patroni_postgresql_listen_address }}:{{ patroni_postgresql_listen_port }} + connect_address: {{ hostvars[inventory_hostname]['ansible_host'] }}:{{ patroni_postgresql_listen_port }} use_unix_socket: true data_dir: {{ patroni_postgresql_home_dir }}/{{ patroni_postgresql_major_version }}/{{ patroni_postgresql_cluster_name }} bin_dir: {{ patroni_postgresql_bin_dir }}