Skip to content

Commit 92e4881

Browse files
authored
fix: duplicate HAProxy IPs in connection info (#1208)
1 parent 3caf73b commit 92e4881

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

automation/molecule/tests/roles/deploy-finish/variables/haproxy_nodes.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
groups['balancers']
1616
| default([])
1717
| map('extract', hostvars, 'inventory_hostname')
18-
| join(',')
18+
| join(', ')
1919
}}
2020
2121
# 🖨️ Debugging the established haproxy_nodes
@@ -32,7 +32,7 @@
3232
that:
3333
- "haproxy_nodes is not none"
3434
- "haproxy_nodes != 'N/A'"
35-
- "haproxy_nodes == 'una.name,10.172.0.21,10.172.0.22'"
35+
- "haproxy_nodes == 'una.name, 10.172.0.21, 10.172.0.22'"
3636
fail_msg: "Test failed: haproxy_nodes is not set correctly."
3737
success_msg: "Test passed: haproxy_nodes is set correctly."
3838

@@ -49,7 +49,7 @@
4949
groups['postgres_cluster']
5050
| default([])
5151
| map('extract', hostvars, 'inventory_hostname')
52-
| join(',')
52+
| join(', ')
5353
}}
5454
5555
# 🖨️ Debugging the established postgres_cluster_nodes
@@ -66,6 +66,6 @@
6666
that:
6767
- "postgres_cluster_nodes is not none"
6868
- "postgres_cluster_nodes != 'N/A'"
69-
- "postgres_cluster_nodes == 'una.name,10.172.0.21,10.172.0.22'"
69+
- "postgres_cluster_nodes == 'una.name, 10.172.0.21, 10.172.0.22'"
7070
fail_msg: "Test failed: postgres_cluster_nodes is not set correctly."
7171
success_msg: "Test passed: postgres_cluster_nodes is set correctly."

automation/roles/deploy_finish/tasks/main.yml

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,23 @@
146146
when: not with_haproxy_load_balancing | bool and not pgbouncer_install | bool
147147
ignore_errors: true
148148
vars:
149-
public_haproxy_ip_addresses: "{{ groups['balancers'] | default([]) | map('extract', hostvars, 'ansible_ssh_host') | join(',') }}"
150-
public_postgres_ip_addresses: "{{ groups['postgres_cluster'] | default([]) | map('extract', hostvars, 'ansible_ssh_host') | join(',') }}"
151-
haproxy_ip_addresses: "{{ groups['balancers'] | default([]) | map('extract', hostvars) | map(attribute='haproxy_bind_address', default=bind_address) | join(',') }}"
152-
postgres_ip_addresses: "{{ groups['postgres_cluster'] | default([]) | map('extract', hostvars) | map(attribute='patroni_bind_address', default=bind_address) | join(',') }}"
149+
public_haproxy_ip_addresses: "{{ groups['balancers'] | default([]) | map('extract', hostvars, 'ansible_ssh_host') | join(', ') }}"
150+
public_postgres_ip_addresses: "{{ groups['postgres_cluster'] | default([]) | map('extract', hostvars, 'ansible_ssh_host') | join(', ') }}"
151+
haproxy_ip_addresses: >-
152+
{{
153+
(groups['balancers'] | default([]) | map('extract', hostvars, 'haproxy_bind_address') | map('default', None, True) | list)
154+
| zip(groups['balancers'] | default([]) | map('extract', hostvars, 'bind_address') | map('default', None, True) | list)
155+
| map('list') | map('select', 'truthy') | map('first') | unique | join(', ')
156+
}}
157+
postgres_ip_addresses: >-
158+
{{
159+
(groups['postgres_cluster'] | default([]) | map('extract', hostvars, 'patroni_bind_address') | map('default', None, True) | list)
160+
| zip(groups['postgres_cluster'] | default([]) | map('extract', hostvars, 'bind_address') | map('default', None, True) | list)
161+
| map('list') | map('select', 'truthy') | map('first') | unique | join(', ')
162+
}}
153163
superuser_username: "{{ patroni_superuser_username }}"
154164
superuser_password: "{{ '********' if mask_password | default(false) | bool else patroni_superuser_password }}"
155-
libpq_postgres_host_port: "{{ postgres_ip_addresses.split(',') | map('regex_replace', '$', ':' + postgresql_port | string) | join(',') }}"
165+
libpq_postgres_host_port: "{{ postgres_ip_addresses.split(',') | map('regex_replace', '$', ':' + postgresql_port | string) | join(', ') }}"
156166
libpq_load_balance: "{{ '&load_balance_hosts=random' if postgresql_version | int >= 16 else '' }}"
157167
when:
158168
- (cluster_vip is not defined or cluster_vip | length < 1)

0 commit comments

Comments
 (0)