diff --git a/inventory b/inventory index 05ebcb6ba..1c88b49ee 100644 --- a/inventory +++ b/inventory @@ -2,14 +2,12 @@ # The specified ip addresses will be used to listen by the cluster components. # Attention! Specify private IP addresses so that the cluster does not listen a public IP addresses. # For deploying via public IPs, add 'ansible_host=public_ip_address' variable for each node. - -# "postgresql_exists='true'" if PostgreSQL is already exists and running +# +# "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). +# patroni_tags="key=value" the Patroni tags in "key=value" format separated by commas. +# balancer_tags="key=value" the Balancer tags for the /replica, /sync, /async endpoints. Add the tag to the 'patroni_tags' variable first. # if dcs_exists: false and dcs_type: "etcd" [etcd_cluster] # recommendation: 3, or 5-7 nodes @@ -61,6 +59,6 @@ ansible_user='localadm' ansible_python_interpreter='/usr/libexec/platform-python' [pgbackrest:vars] -ansible_user='postgres' -ansible_ssh_pass='secretpassword' +#ansible_user='postgres' +#ansible_ssh_pass='secretpassword' diff --git a/molecule/default/converge.yml b/molecule/default/converge.yml index 1725f95b3..68c906337 100644 --- a/molecule/default/converge.yml +++ b/molecule/default/converge.yml @@ -19,6 +19,7 @@ postgresql_version: "16" # to test custom WAL dir pgbouncer_processes: 2 # Test multiple pgbouncer processes (so_reuseport) patroni_tags: "datacenter=dc1,key1=value1" + balancer_tags: "datacenter=dc1" cacheable: true delegate_to: localhost run_once: true # noqa run-once diff --git a/roles/confd/templates/haproxy.tmpl.j2 b/roles/confd/templates/haproxy.tmpl.j2 index c3d801c2b..6bc123569 100644 --- a/roles/confd/templates/haproxy.tmpl.j2 +++ b/roles/confd/templates/haproxy.tmpl.j2 @@ -69,7 +69,7 @@ listen replicas {% endif %} maxconn {{ haproxy_maxconn.replica }} option tcplog - option httpchk OPTIONS /replica?lag={{ patroni_maximum_lag_on_replica }} + option httpchk OPTIONS /replica?lag={{ patroni_maximum_lag_on_replica }}{% if balancer_tags | default('') | length > 0 %}{{ '&' + balancer_tags.split(',') | map('trim') | map('regex_replace', '([^=]+)=(.*)', 'tag_\\1=\\2') | join('&') + '\n' }}{% endif %} balance roundrobin http-check expect status 200 default-server inter 3s fastinter 1s fall 3 rise 2 on-marked-down shutdown-sessions @@ -91,7 +91,7 @@ listen replicas_direct {% endif %} maxconn {{ haproxy_maxconn.replica }} option tcplog - option httpchk OPTIONS /replica?lag={{ patroni_maximum_lag_on_replica }} + option httpchk OPTIONS /replica?lag={{ patroni_maximum_lag_on_replica }}{% if balancer_tags | default('') | length > 0 %}{{ '&' + balancer_tags.split(',') | map('trim') | map('regex_replace', '([^=]+)=(.*)', 'tag_\\1=\\2') | join('&') + '\n' }}{% endif %} balance roundrobin http-check expect status 200 default-server inter 3s fastinter 1s fall 3 rise 2 on-marked-down shutdown-sessions @@ -107,7 +107,7 @@ listen replicas_sync {% endif %} maxconn {{ haproxy_maxconn.replica }} option tcplog - option httpchk OPTIONS /sync + option httpchk OPTIONS /sync{% if balancer_tags | default('') | length > 0 %}{{ '?' + balancer_tags.split(',') | map('trim') | map('regex_replace', '([^=]+)=(.*)', 'tag_\\1=\\2') | join('&') + '\n' }}{% endif %} balance roundrobin http-check expect status 200 default-server inter 3s fastinter 1s fall 3 rise 2 on-marked-down shutdown-sessions @@ -129,7 +129,7 @@ listen replicas_sync_direct {% endif %} maxconn {{ haproxy_maxconn.replica }} option tcplog - option httpchk OPTIONS /sync + option httpchk OPTIONS /sync{% if balancer_tags | default('') | length > 0 %}{{ '?' + balancer_tags.split(',') | map('trim') | map('regex_replace', '([^=]+)=(.*)', 'tag_\\1=\\2') | join('&') + '\n' }}{% endif %} balance roundrobin http-check expect status 200 default-server inter 3s fastinter 1s fall 3 rise 2 on-marked-down shutdown-sessions @@ -145,7 +145,7 @@ listen replicas_async {% endif %} maxconn {{ haproxy_maxconn.replica }} option tcplog - option httpchk OPTIONS /async?lag={{ patroni_maximum_lag_on_replica }} + option httpchk OPTIONS /async?lag={{ patroni_maximum_lag_on_replica }}{% if balancer_tags | default('') | length > 0 %}{{ '&' + balancer_tags.split(',') | map('trim') | map('regex_replace', '([^=]+)=(.*)', 'tag_\\1=\\2') | join('&') + '\n' }}{% endif %} balance roundrobin http-check expect status 200 default-server inter 3s fastinter 1s fall 3 rise 2 on-marked-down shutdown-sessions @@ -167,7 +167,7 @@ listen replicas_async_direct {% endif %} maxconn {{ haproxy_maxconn.replica }} option tcplog - option httpchk OPTIONS /async?lag={{ patroni_maximum_lag_on_replica }} + option httpchk OPTIONS /async?lag={{ patroni_maximum_lag_on_replica }}{% if balancer_tags | default('') | length > 0 %}{{ '&' + balancer_tags.split(',') | map('trim') | map('regex_replace', '([^=]+)=(.*)', 'tag_\\1=\\2') | join('&') + '\n' }}{% endif %} balance roundrobin http-check expect status 200 default-server inter 3s fastinter 1s fall 3 rise 2 on-marked-down shutdown-sessions diff --git a/roles/haproxy/templates/haproxy.cfg.j2 b/roles/haproxy/templates/haproxy.cfg.j2 index b64d36ac9..1e0e56084 100644 --- a/roles/haproxy/templates/haproxy.cfg.j2 +++ b/roles/haproxy/templates/haproxy.cfg.j2 @@ -72,7 +72,7 @@ listen replicas {% endif %} maxconn {{ haproxy_maxconn.replica }} option tcplog - option httpchk OPTIONS /replica?lag={{ patroni_maximum_lag_on_replica }} + option httpchk OPTIONS /replica?lag={{ patroni_maximum_lag_on_replica }}{% if balancer_tags | default('') | length > 0 %}{{ '&' + balancer_tags.split(',') | map('trim') | map('regex_replace', '([^=]+)=(.*)', 'tag_\\1=\\2') | join('&') + '\n' }}{% endif %} balance roundrobin http-check expect status 200 default-server inter 3s fastinter 1s fall 3 rise 2 on-marked-down shutdown-sessions @@ -96,7 +96,7 @@ listen replicas_direct {% endif %} maxconn {{ haproxy_maxconn.replica }} option tcplog - option httpchk OPTIONS /replica?lag={{ patroni_maximum_lag_on_replica }} + option httpchk OPTIONS /replica?lag={{ patroni_maximum_lag_on_replica }}{% if balancer_tags | default('') | length > 0 %}{{ '&' + balancer_tags.split(',') | map('trim') | map('regex_replace', '([^=]+)=(.*)', 'tag_\\1=\\2') | join('&') + '\n' }}{% endif %} balance roundrobin http-check expect status 200 default-server inter 3s fastinter 1s fall 3 rise 2 on-marked-down shutdown-sessions @@ -113,7 +113,7 @@ listen replicas_sync {% endif %} maxconn {{ haproxy_maxconn.replica }} option tcplog - option httpchk OPTIONS /sync + option httpchk OPTIONS /sync{% if balancer_tags | default('') | length > 0 %}{{ '?' + balancer_tags.split(',') | map('trim') | map('regex_replace', '([^=]+)=(.*)', 'tag_\\1=\\2') | join('&') + '\n' }}{% endif %} balance roundrobin http-check expect status 200 default-server inter 3s fastinter 1s fall 3 rise 2 on-marked-down shutdown-sessions @@ -137,7 +137,7 @@ listen replicas_sync_direct {% endif %} maxconn {{ haproxy_maxconn.replica }} option tcplog - option httpchk OPTIONS /sync + option httpchk OPTIONS /sync{% if balancer_tags | default('') | length > 0 %}{{ '?' + balancer_tags.split(',') | map('trim') | map('regex_replace', '([^=]+)=(.*)', 'tag_\\1=\\2') | join('&') + '\n' }}{% endif %} balance roundrobin http-check expect status 200 default-server inter 3s fastinter 1s fall 3 rise 2 on-marked-down shutdown-sessions @@ -154,7 +154,7 @@ listen replicas_async {% endif %} maxconn {{ haproxy_maxconn.replica }} option tcplog - option httpchk OPTIONS /async?lag={{ patroni_maximum_lag_on_replica }} + option httpchk OPTIONS /async?lag={{ patroni_maximum_lag_on_replica }}{% if balancer_tags | default('') | length > 0 %}{{ '&' + balancer_tags.split(',') | map('trim') | map('regex_replace', '([^=]+)=(.*)', 'tag_\\1=\\2') | join('&') + '\n' }}{% endif %} balance roundrobin http-check expect status 200 default-server inter 3s fastinter 1s fall 3 rise 2 on-marked-down shutdown-sessions @@ -178,7 +178,7 @@ listen replicas_async_direct {% endif %} maxconn {{ haproxy_maxconn.replica }} option tcplog - option httpchk OPTIONS /async?lag={{ patroni_maximum_lag_on_replica }} + option httpchk OPTIONS /async?lag={{ patroni_maximum_lag_on_replica }}{% if balancer_tags | default('') | length > 0 %}{{ '&' + balancer_tags.split(',') | map('trim') | map('regex_replace', '([^=]+)=(.*)', 'tag_\\1=\\2') | join('&') + '\n' }}{% endif %} balance roundrobin http-check expect status 200 default-server inter 3s fastinter 1s fall 3 rise 2 on-marked-down shutdown-sessions