Skip to content

Commit a46714e

Browse files
authored
Add patroni_restapi_listen_addr and postgresql_listen_addr variables (vitabaks#598)
1 parent 80901cc commit a46714e

File tree

10 files changed

+46
-48
lines changed

10 files changed

+46
-48
lines changed

roles/confd/templates/haproxy.tmpl.j2

+9-9
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ defaults
2121

2222
listen stats
2323
mode http
24-
bind {{ hostvars[inventory_hostname]['inventory_hostname'] }}:{{ haproxy_listen_port.stats }}
24+
bind {{ inventory_hostname }}:{{ haproxy_listen_port.stats }}
2525
stats enable
2626
stats uri /
2727

2828
listen master
2929
{% if cluster_vip is defined and cluster_vip | length > 0 %}
3030
bind {{ cluster_vip }}:{{ haproxy_listen_port.master }}
3131
{% else %}
32-
bind {{ hostvars[inventory_hostname]['inventory_hostname'] }}:{{ haproxy_listen_port.master }}
32+
bind {{ inventory_hostname }}:{{ haproxy_listen_port.master }}
3333
{% endif %}
3434
maxconn {{ haproxy_maxconn.master }}
3535
option tcplog
@@ -50,7 +50,7 @@ listen master_direct
5050
{% if cluster_vip is defined and cluster_vip | length > 0 %}
5151
bind {{ cluster_vip }}:{{ haproxy_listen_port.master_direct }}
5252
{% else %}
53-
bind {{ hostvars[inventory_hostname]['inventory_hostname'] }}:{{ haproxy_listen_port.master_direct }}
53+
bind {{ inventory_hostname }}:{{ haproxy_listen_port.master_direct }}
5454
{% endif %}
5555
maxconn {{ haproxy_maxconn.master }}
5656
option tcplog
@@ -65,7 +65,7 @@ listen replicas
6565
{% if cluster_vip is defined and cluster_vip | length > 0 %}
6666
bind {{ cluster_vip }}:{{ haproxy_listen_port.replicas }}
6767
{% else %}
68-
bind {{ hostvars[inventory_hostname]['inventory_hostname'] }}:{{ haproxy_listen_port.replicas }}
68+
bind {{ inventory_hostname }}:{{ haproxy_listen_port.replicas }}
6969
{% endif %}
7070
maxconn {{ haproxy_maxconn.replica }}
7171
option tcplog
@@ -87,7 +87,7 @@ listen replicas_direct
8787
{% if cluster_vip is defined and cluster_vip | length > 0 %}
8888
bind {{ cluster_vip }}:{{ haproxy_listen_port.replicas_direct }}
8989
{% else %}
90-
bind {{ hostvars[inventory_hostname]['inventory_hostname'] }}:{{ haproxy_listen_port.replicas_direct }}
90+
bind {{ inventory_hostname }}:{{ haproxy_listen_port.replicas_direct }}
9191
{% endif %}
9292
maxconn {{ haproxy_maxconn.replica }}
9393
option tcplog
@@ -103,7 +103,7 @@ listen replicas_sync
103103
{% if cluster_vip is defined and cluster_vip | length > 0 %}
104104
bind {{ cluster_vip }}:{{ haproxy_listen_port.replicas_sync }}
105105
{% else %}
106-
bind {{ hostvars[inventory_hostname]['inventory_hostname'] }}:{{ haproxy_listen_port.replicas_sync }}
106+
bind {{ inventory_hostname }}:{{ haproxy_listen_port.replicas_sync }}
107107
{% endif %}
108108
maxconn {{ haproxy_maxconn.replica }}
109109
option tcplog
@@ -125,7 +125,7 @@ listen replicas_sync_direct
125125
{% if cluster_vip is defined and cluster_vip | length > 0 %}
126126
bind {{ cluster_vip }}:{{ haproxy_listen_port.replicas_sync_direct }}
127127
{% else %}
128-
bind {{ hostvars[inventory_hostname]['inventory_hostname'] }}:{{ haproxy_listen_port.replicas_sync_direct }}
128+
bind {{ inventory_hostname }}:{{ haproxy_listen_port.replicas_sync_direct }}
129129
{% endif %}
130130
maxconn {{ haproxy_maxconn.replica }}
131131
option tcplog
@@ -141,7 +141,7 @@ listen replicas_async
141141
{% if cluster_vip is defined and cluster_vip | length > 0 %}
142142
bind {{ cluster_vip }}:{{ haproxy_listen_port.replicas_async }}
143143
{% else %}
144-
bind {{ hostvars[inventory_hostname]['inventory_hostname'] }}:{{ haproxy_listen_port.replicas_async }}
144+
bind {{ inventory_hostname }}:{{ haproxy_listen_port.replicas_async }}
145145
{% endif %}
146146
maxconn {{ haproxy_maxconn.replica }}
147147
option tcplog
@@ -163,7 +163,7 @@ listen replicas_async_direct
163163
{% if cluster_vip is defined and cluster_vip | length > 0 %}
164164
bind {{ cluster_vip }}:{{ haproxy_listen_port.replicas_async_direct }}
165165
{% else %}
166-
bind {{ hostvars[inventory_hostname]['inventory_hostname'] }}:{{ haproxy_listen_port.replicas_async_direct }}
166+
bind {{ inventory_hostname }}:{{ haproxy_listen_port.replicas_async_direct }}
167167
{% endif %}
168168
maxconn {{ haproxy_maxconn.replica }}
169169
option tcplog

roles/haproxy/handlers/main.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
- name: Check HAProxy is started and accepting connections
1212
ansible.builtin.wait_for:
1313
port: "{{ haproxy_listen_port.stats }}"
14-
host: "{{ hostvars[inventory_hostname]['inventory_hostname'] }}"
14+
host: "{{ inventory_hostname }}"
1515
state: started
1616
timeout: 120
1717
delay: 10

roles/haproxy/templates/haproxy.cfg.j2

+9-9
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ defaults
2121

2222
listen stats
2323
mode http
24-
bind {{ hostvars[inventory_hostname]['inventory_hostname'] }}:{{ haproxy_listen_port.stats }}
24+
bind {{ inventory_hostname }}:{{ haproxy_listen_port.stats }}
2525
stats enable
2626
stats uri /
2727

2828
listen master
2929
{% if cluster_vip is defined and cluster_vip | length > 0 %}
3030
bind {{ cluster_vip }}:{{ haproxy_listen_port.master }}
3131
{% else %}
32-
bind {{ hostvars[inventory_hostname]['inventory_hostname'] }}:{{ haproxy_listen_port.master }}
32+
bind {{ inventory_hostname }}:{{ haproxy_listen_port.master }}
3333
{% endif %}
3434
maxconn {{ haproxy_maxconn.master }}
3535
option tcplog
@@ -52,7 +52,7 @@ listen master_direct
5252
{% if cluster_vip is defined and cluster_vip | length > 0 %}
5353
bind {{ cluster_vip }}:{{ haproxy_listen_port.master_direct }}
5454
{% else %}
55-
bind {{ hostvars[inventory_hostname]['inventory_hostname'] }}:{{ haproxy_listen_port.master_direct }}
55+
bind {{ inventory_hostname }}:{{ haproxy_listen_port.master_direct }}
5656
{% endif %}
5757
maxconn {{ haproxy_maxconn.master }}
5858
option tcplog
@@ -68,7 +68,7 @@ listen replicas
6868
{% if cluster_vip is defined and cluster_vip | length > 0 %}
6969
bind {{ cluster_vip }}:{{ haproxy_listen_port.replicas }}
7070
{% else %}
71-
bind {{ hostvars[inventory_hostname]['inventory_hostname'] }}:{{ haproxy_listen_port.replicas }}
71+
bind {{ inventory_hostname }}:{{ haproxy_listen_port.replicas }}
7272
{% endif %}
7373
maxconn {{ haproxy_maxconn.replica }}
7474
option tcplog
@@ -92,7 +92,7 @@ listen replicas_direct
9292
{% if cluster_vip is defined and cluster_vip | length > 0 %}
9393
bind {{ cluster_vip }}:{{ haproxy_listen_port.replicas_direct }}
9494
{% else %}
95-
bind {{ hostvars[inventory_hostname]['inventory_hostname'] }}:{{ haproxy_listen_port.replicas_direct }}
95+
bind {{ inventory_hostname }}:{{ haproxy_listen_port.replicas_direct }}
9696
{% endif %}
9797
maxconn {{ haproxy_maxconn.replica }}
9898
option tcplog
@@ -109,7 +109,7 @@ listen replicas_sync
109109
{% if cluster_vip is defined and cluster_vip | length > 0 %}
110110
bind {{ cluster_vip }}:{{ haproxy_listen_port.replicas_sync }}
111111
{% else %}
112-
bind {{ hostvars[inventory_hostname]['inventory_hostname'] }}:{{ haproxy_listen_port.replicas_sync }}
112+
bind {{ inventory_hostname }}:{{ haproxy_listen_port.replicas_sync }}
113113
{% endif %}
114114
maxconn {{ haproxy_maxconn.replica }}
115115
option tcplog
@@ -133,7 +133,7 @@ listen replicas_sync_direct
133133
{% if cluster_vip is defined and cluster_vip | length > 0 %}
134134
bind {{ cluster_vip }}:{{ haproxy_listen_port.replicas_sync_direct }}
135135
{% else %}
136-
bind {{ hostvars[inventory_hostname]['inventory_hostname'] }}:{{ haproxy_listen_port.replicas_sync_direct }}
136+
bind {{ inventory_hostname }}:{{ haproxy_listen_port.replicas_sync_direct }}
137137
{% endif %}
138138
maxconn {{ haproxy_maxconn.replica }}
139139
option tcplog
@@ -150,7 +150,7 @@ listen replicas_async
150150
{% if cluster_vip is defined and cluster_vip | length > 0 %}
151151
bind {{ cluster_vip }}:{{ haproxy_listen_port.replicas_async }}
152152
{% else %}
153-
bind {{ hostvars[inventory_hostname]['inventory_hostname'] }}:{{ haproxy_listen_port.replicas_async }}
153+
bind {{ inventory_hostname }}:{{ haproxy_listen_port.replicas_async }}
154154
{% endif %}
155155
maxconn {{ haproxy_maxconn.replica }}
156156
option tcplog
@@ -174,7 +174,7 @@ listen replicas_async_direct
174174
{% if cluster_vip is defined and cluster_vip | length > 0 %}
175175
bind {{ cluster_vip }}:{{ haproxy_listen_port.replicas_async_direct }}
176176
{% else %}
177-
bind {{ hostvars[inventory_hostname]['inventory_hostname'] }}:{{ haproxy_listen_port.replicas_async_direct }}
177+
bind {{ inventory_hostname }}:{{ haproxy_listen_port.replicas_async_direct }}
178178
{% endif %}
179179
maxconn {{ haproxy_maxconn.replica }}
180180
option tcplog

roles/patroni/config/tasks/main.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
- block:
4343
- name: Update postgresql parameters in DCS
4444
ansible.builtin.uri:
45-
url: http://{{ hostvars[inventory_hostname]['inventory_hostname'] }}:{{ patroni_restapi_port }}/config
45+
url: http://{{ inventory_hostname }}:{{ patroni_restapi_port }}/config
4646
method: PATCH
4747
body: '{"postgresql":{"parameters":{"{{ item.option }}":"{{ item.value }}"}}}'
4848
body_format: json
@@ -51,7 +51,7 @@
5151

5252
- name: Delete postgresql parameters from DCS
5353
ansible.builtin.uri:
54-
url: http://{{ hostvars[inventory_hostname]['inventory_hostname'] }}:{{ patroni_restapi_port }}/config
54+
url: http://{{ inventory_hostname }}:{{ patroni_restapi_port }}/config
5555
method: PATCH
5656
body: '{"postgresql":{"parameters":{"{{ item.option }}":null}}}'
5757
body_format: json

roles/patroni/tasks/custom_wal_dir.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@
9898
- name: "Wait for port {{ patroni_restapi_port }} to become open on the host"
9999
ansible.builtin.wait_for:
100100
port: "{{ patroni_restapi_port }}"
101-
host: "{{ hostvars[inventory_hostname]['inventory_hostname'] }}"
101+
host: "{{ inventory_hostname }}"
102102
state: started
103103
timeout: 120
104104
delay: 10
@@ -107,7 +107,7 @@
107107

108108
- name: Check that the patroni is healthy (the leader with the lock)
109109
ansible.builtin.uri:
110-
url: "http://{{ hostvars[inventory_hostname]['inventory_hostname'] }}:{{ patroni_restapi_port }}/leader"
110+
url: "http://{{ inventory_hostname }}:{{ patroni_restapi_port }}/leader"
111111
status_code: 200
112112
register: patroni_result
113113
until: patroni_result.status == 200
@@ -128,7 +128,7 @@
128128
- name: "Wait for port {{ patroni_restapi_port }} to become open on the host"
129129
ansible.builtin.wait_for:
130130
port: "{{ patroni_restapi_port }}"
131-
host: "{{ hostvars[inventory_hostname]['inventory_hostname'] }}"
131+
host: "{{ inventory_hostname }}"
132132
state: started
133133
timeout: 120
134134
delay: 10
@@ -137,7 +137,7 @@
137137

138138
- name: Check that the patroni is healthy on the Replica
139139
ansible.builtin.uri:
140-
url: "http://{{ hostvars[inventory_hostname]['inventory_hostname'] }}:{{ patroni_restapi_port }}/health"
140+
url: "http://{{ inventory_hostname }}:{{ patroni_restapi_port }}/health"
141141
status_code: 200
142142
register: patroni_result
143143
until: patroni_result.status == 200

roles/patroni/tasks/main.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,7 @@
780780
- name: "Wait for port {{ patroni_restapi_port }} to become open on the host"
781781
ansible.builtin.wait_for:
782782
port: "{{ patroni_restapi_port }}"
783-
host: "{{ hostvars[inventory_hostname]['inventory_hostname'] }}"
783+
host: "{{ inventory_hostname }}"
784784
state: started
785785
timeout: 120
786786
delay: 10
@@ -813,7 +813,7 @@
813813

814814
- name: Wait for the cluster to initialize (master is the leader with the lock)
815815
ansible.builtin.uri:
816-
url: "http://{{ hostvars[inventory_hostname]['inventory_hostname'] }}:{{ patroni_restapi_port }}/leader"
816+
url: "http://{{ inventory_hostname }}:{{ patroni_restapi_port }}/leader"
817817
status_code: 200
818818
register: result
819819
until: result.status == 200
@@ -955,15 +955,15 @@
955955
- name: "Wait for port {{ patroni_restapi_port }} to become open on the host"
956956
ansible.builtin.wait_for:
957957
port: "{{ patroni_restapi_port }}"
958-
host: "{{ hostvars[inventory_hostname]['inventory_hostname'] }}"
958+
host: "{{ inventory_hostname }}"
959959
state: started
960960
timeout: 120
961961
delay: 10
962962
ignore_errors: false
963963

964964
- name: Check that the patroni is healthy on the replica server
965965
ansible.builtin.uri:
966-
url: "http://{{ hostvars[inventory_hostname]['inventory_hostname'] }}:{{ patroni_restapi_port }}/health"
966+
url: "http://{{ inventory_hostname }}:{{ patroni_restapi_port }}/health"
967967
status_code: 200
968968
register: replica_result
969969
until: replica_result.status == 200

roles/patroni/templates/patroni.yml.j2

+4-8
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ log:
2121
{% endif %}
2222

2323
restapi:
24-
listen: {{ hostvars[inventory_hostname]['inventory_hostname'] }}:{{ patroni_restapi_port }}
25-
connect_address: {{ hostvars[inventory_hostname]['inventory_hostname'] }}:{{ patroni_restapi_port }}
24+
listen: {{ patroni_restapi_listen_addr }}:{{ patroni_restapi_port }}
25+
connect_address: {{ inventory_hostname }}:{{ patroni_restapi_port }}
2626
# certfile: /etc/ssl/certs/ssl-cert-snakeoil.pem
2727
# keyfile: /etc/ssl/private/ssl-cert-snakeoil.key
2828
# authentication:
@@ -121,12 +121,8 @@ bootstrap:
121121

122122

123123
postgresql:
124-
{% if not with_haproxy_load_balancing|bool and not pgbouncer_install|bool and (cluster_vip is defined and cluster_vip | length > 0) %}
125-
listen: {{ hostvars[inventory_hostname]['inventory_hostname'] }},{{ cluster_vip }},127.0.0.1:{{ postgresql_port }}
126-
{% else %}
127-
listen: {{ hostvars[inventory_hostname]['inventory_hostname'] }},127.0.0.1:{{ postgresql_port }}
128-
{% endif %}
129-
connect_address: {{ hostvars[inventory_hostname]['inventory_hostname'] }}:{{ postgresql_port }}
124+
listen: {{ postgresql_listen_addr }}:{{ postgresql_port }}
125+
connect_address: {{ inventory_hostname }}:{{ postgresql_port }}
130126
{% if patroni_superuser_username == 'postgres' %}
131127
use_unix_socket: true
132128
{% endif %}

roles/pgbouncer/handlers/main.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
- name: Wait for port "{{ pgbouncer_listen_port }}" to become open on the host
1515
ansible.builtin.wait_for:
1616
port: "{{ pgbouncer_listen_port }}"
17-
host: "{{ hostvars[inventory_hostname]['inventory_hostname'] }}"
17+
host: "{{ inventory_hostname }}"
1818
state: started
1919
timeout: 120
2020
delay: 5

roles/upgrade/templates/haproxy-no-http-checks.cfg.j2

+9-9
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ defaults
2121

2222
listen stats
2323
mode http
24-
bind {{ hostvars[inventory_hostname]['inventory_hostname'] }}:{{ haproxy_listen_port.stats }}
24+
bind {{ inventory_hostname }}:{{ haproxy_listen_port.stats }}
2525
stats enable
2626
stats uri /
2727

2828
listen master
2929
{% if cluster_vip is defined and cluster_vip | length > 0 %}
3030
bind {{ cluster_vip }}:{{ haproxy_listen_port.master }}
3131
{% else %}
32-
bind {{ hostvars[inventory_hostname]['inventory_hostname'] }}:{{ haproxy_listen_port.master }}
32+
bind {{ inventory_hostname }}:{{ haproxy_listen_port.master }}
3333
{% endif %}
3434
maxconn {{ haproxy_maxconn.master }}
3535
option tcplog
@@ -42,7 +42,7 @@ listen master_direct
4242
{% if cluster_vip is defined and cluster_vip | length > 0 %}
4343
bind {{ cluster_vip }}:{{ haproxy_listen_port.master_direct }}
4444
{% else %}
45-
bind {{ hostvars[inventory_hostname]['inventory_hostname'] }}:{{ haproxy_listen_port.master_direct }}
45+
bind {{ inventory_hostname }}:{{ haproxy_listen_port.master_direct }}
4646
{% endif %}
4747
maxconn {{ haproxy_maxconn.master }}
4848
option tcplog
@@ -55,7 +55,7 @@ listen replicas
5555
{% if cluster_vip is defined and cluster_vip | length > 0 %}
5656
bind {{ cluster_vip }}:{{ haproxy_listen_port.replicas }}
5757
{% else %}
58-
bind {{ hostvars[inventory_hostname]['inventory_hostname'] }}:{{ haproxy_listen_port.replicas }}
58+
bind {{ inventory_hostname }}:{{ haproxy_listen_port.replicas }}
5959
{% endif %}
6060
maxconn {{ haproxy_maxconn.replica }}
6161
option tcplog
@@ -69,7 +69,7 @@ listen replicas_direct
6969
{% if cluster_vip is defined and cluster_vip | length > 0 %}
7070
bind {{ cluster_vip }}:{{ haproxy_listen_port.replicas_direct }}
7171
{% else %}
72-
bind {{ hostvars[inventory_hostname]['inventory_hostname'] }}:{{ haproxy_listen_port.replicas_direct }}
72+
bind {{ inventory_hostname }}:{{ haproxy_listen_port.replicas_direct }}
7373
{% endif %}
7474
maxconn {{ haproxy_maxconn.replica }}
7575
option tcplog
@@ -83,7 +83,7 @@ listen replicas_sync
8383
{% if cluster_vip is defined and cluster_vip | length > 0 %}
8484
bind {{ cluster_vip }}:{{ haproxy_listen_port.replicas_sync }}
8585
{% else %}
86-
bind {{ hostvars[inventory_hostname]['inventory_hostname'] }}:{{ haproxy_listen_port.replicas_sync }}
86+
bind {{ inventory_hostname }}:{{ haproxy_listen_port.replicas_sync }}
8787
{% endif %}
8888
maxconn {{ haproxy_maxconn.replica }}
8989
option tcplog
@@ -97,7 +97,7 @@ listen replicas_sync_direct
9797
{% if cluster_vip is defined and cluster_vip | length > 0 %}
9898
bind {{ cluster_vip }}:{{ haproxy_listen_port.replicas_sync_direct }}
9999
{% else %}
100-
bind {{ hostvars[inventory_hostname]['inventory_hostname'] }}:{{ haproxy_listen_port.replicas_sync_direct }}
100+
bind {{ inventory_hostname }}:{{ haproxy_listen_port.replicas_sync_direct }}
101101
{% endif %}
102102
maxconn {{ haproxy_maxconn.replica }}
103103
option tcplog
@@ -111,7 +111,7 @@ listen replicas_async
111111
{% if cluster_vip is defined and cluster_vip | length > 0 %}
112112
bind {{ cluster_vip }}:{{ haproxy_listen_port.replicas_async }}
113113
{% else %}
114-
bind {{ hostvars[inventory_hostname]['inventory_hostname'] }}:{{ haproxy_listen_port.replicas_async }}
114+
bind {{ inventory_hostname }}:{{ haproxy_listen_port.replicas_async }}
115115
{% endif %}
116116
maxconn {{ haproxy_maxconn.replica }}
117117
option tcplog
@@ -125,7 +125,7 @@ listen replicas_async_direct
125125
{% if cluster_vip is defined and cluster_vip | length > 0 %}
126126
bind {{ cluster_vip }}:{{ haproxy_listen_port.replicas_async_direct }}
127127
{% else %}
128-
bind {{ hostvars[inventory_hostname]['inventory_hostname'] }}:{{ haproxy_listen_port.replicas_async_direct }}
128+
bind {{ inventory_hostname }}:{{ haproxy_listen_port.replicas_async_direct }}
129129
{% endif %}
130130
maxconn {{ haproxy_maxconn.replica }}
131131
option tcplog

0 commit comments

Comments
 (0)