From d81229d45c622bd40488ec059b5f312a40cf20f0 Mon Sep 17 00:00:00 2001 From: Vitaliy Kukharik <37010174+vitabaks@users.noreply.github.com> Date: Thu, 28 Mar 2024 10:30:16 +0300 Subject: [PATCH] Add the ability to set Patroni tags (including custom tags) at the host level (#611) Adding ability to runn flawless on AlmaLinux --- inventory | 1 + molecule/default/converge.yml | 1 + roles/patroni/templates/patroni.yml.j2 | 16 ++++++++++++++-- vars/main.yml | 6 +++--- 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/inventory b/inventory index 84b9a7776..05ebcb6ba 100644 --- a/inventory +++ b/inventory @@ -6,6 +6,7 @@ # "postgresql_exists='true'" if PostgreSQL is already exists and running # "hostname=" variable is optional (used to change the server name) # "new_node=true" to add a new server to an existing cluster using the add_pgnode.yml playbook +# patroni_tags="key=value" tags for Patroni in "key=value" format separated by commas (details here: https://patroni.readthedocs.io/en/latest/yaml_configuration.html#tags) # In this example, all components will be installed on PostgreSQL nodes. # You can deploy the haproxy balancers and the etcd or consul cluster on other dedicated servers (recomended). diff --git a/molecule/default/converge.yml b/molecule/default/converge.yml index cbfdb5c26..1725f95b3 100644 --- a/molecule/default/converge.yml +++ b/molecule/default/converge.yml @@ -18,6 +18,7 @@ consul_bootstrap_expect: true # if dcs_type: "consul" postgresql_version: "16" # to test custom WAL dir pgbouncer_processes: 2 # Test multiple pgbouncer processes (so_reuseport) + patroni_tags: "datacenter=dc1,key1=value1" cacheable: true delegate_to: localhost run_once: true # noqa run-once diff --git a/roles/patroni/templates/patroni.yml.j2 b/roles/patroni/templates/patroni.yml.j2 index 743c7d7a1..d943e6af1 100644 --- a/roles/patroni/templates/patroni.yml.j2 +++ b/roles/patroni/templates/patroni.yml.j2 @@ -211,10 +211,22 @@ watchdog: safety_margin: 5 tags: - nofailover: false +{% if patroni_tags is defined and patroni_tags | length > 0 %} + {{ patroni_tags | replace(" ", "") | replace("=", ": ") | replace(",", "\n ") }} +{% endif %} +{% set normalized_tags = patroni_tags | default('') | replace(" ", "") %} +{% if 'nosync=' not in normalized_tags %} + nosync: false +{% endif %} +{% if 'noloadbalance=' not in normalized_tags %} noloadbalance: false +{% endif %} +{% if 'nofailover=' not in normalized_tags %} + nofailover: false +{% endif %} +{% if 'clonefrom=' not in normalized_tags %} clonefrom: false - nosync: false +{% endif %} # specify a node to replicate from (cascading replication) # replicatefrom: (node name) diff --git a/vars/main.yml b/vars/main.yml index 5f9026bc7..b8d5581f3 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -83,8 +83,8 @@ patroni_etcd_password: "" # (optional) password for etcd authentication patroni_etcd_protocol: "" # (optional) http or https, if not specified http is used # more options you can specify in the roles/patroni/templates/patroni.yml.j2 -# https://patroni.readthedocs.io/en/latest/SETTINGS.html#etcd -# https://patroni.readthedocs.io/en/latest/SETTINGS.html#consul +# https://patroni.readthedocs.io/en/latest/yaml_configuration.html#etcd +# https://patroni.readthedocs.io/en/latest/yaml_configuration.html#consul # if dcs_type: "consul" consul_version: "1.15.8" @@ -343,7 +343,7 @@ patroni_master_start_timeout: 300 patroni_maximum_lag_on_failover: 1048576 # (1MB) the maximum bytes a follower may lag to be able to participate in leader election. patroni_maximum_lag_on_replica: "100MB" # the maximum of lag that replica can be in order to be available for read-only queries. -# https://patroni.readthedocs.io/en/latest/SETTINGS.html?highlight=callbacks#dynamic-configuration-settings +# https://patroni.readthedocs.io/en/latest/yaml_configuration.html#postgresql patroni_callbacks: [] # - {action: "on_role_change", script: ""} # - {action: "on_stop", script: ""}