Skip to content

Commit

Permalink
Add the ability to set Patroni tags (including custom tags) at the ho…
Browse files Browse the repository at this point in the history
…st level (vitabaks#611)

Adding ability to runn flawless on AlmaLinux
  • Loading branch information
vitabaks authored and christofalpo committed Apr 22, 2024
1 parent 7d08f68 commit d81229d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
1 change: 1 addition & 0 deletions inventory
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
1 change: 1 addition & 0 deletions molecule/default/converge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 14 additions & 2 deletions roles/patroni/templates/patroni.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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: ""}
Expand Down

0 comments on commit d81229d

Please sign in to comment.