From 139f56797ce6852f152fc991450c39641e3f5b76 Mon Sep 17 00:00:00 2001 From: Vitaliy Kukharik <37010174+vitabaks@users.noreply.github.com> Date: Mon, 18 Dec 2023 17:53:10 +0300 Subject: [PATCH] Fix: Skip creating DB users and functions in Standby Cluster leader (#533) --- roles/pgbouncer/config/tasks/main.yml | 4 +++- roles/postgresql-users/tasks/main.yml | 9 ++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/roles/pgbouncer/config/tasks/main.yml b/roles/pgbouncer/config/tasks/main.yml index c34e97a68..0e8c999a0 100644 --- a/roles/pgbouncer/config/tasks/main.yml +++ b/roles/pgbouncer/config/tasks/main.yml @@ -69,7 +69,9 @@ '; done args: executable: /bin/bash - when: pgbouncer_auth_user|bool and is_master|bool + when: + - pgbouncer_auth_user | bool + - (is_master | bool and patroni_standby_cluster.host | default('') | length < 1) # do not perform on the Standby Cluster leader tags: pgbouncer, pgbouncer_conf, pgbouncer_auth_query ... diff --git a/roles/postgresql-users/tasks/main.yml b/roles/postgresql-users/tasks/main.yml index c9e47bce0..de0b700ca 100644 --- a/roles/postgresql-users/tasks/main.yml +++ b/roles/postgresql-users/tasks/main.yml @@ -18,7 +18,10 @@ loop: "{{ postgresql_users | flatten(1) }}" loop_control: label: "{{ item.name }}" - when: postgresql_users is defined and postgresql_users | length > 0 + when: + - postgresql_users | default('') | length > 0 + - item.password | default('') | length > 0 # Ensure the password is not empty + - patroni_standby_cluster.host | default('') | length < 1 # do not perform on the Standby Cluster leader tags: postgresql_users - name: Grant roles to users @@ -35,9 +38,9 @@ loop_control: label: "{{ item.name }}" when: - - postgresql_users is defined - - postgresql_users | length > 0 + - postgresql_users | default('') | length > 0 - item.role | default('') | length > 0 + - patroni_standby_cluster.host | default('') | length < 1 # do not perform on the Standby Cluster leader tags: postgresql_users ...