Skip to content

Commit 7474ba3

Browse files
committed
haproxy: add haproxy_listen_port variables
1 parent 0417a84 commit 7474ba3

File tree

3 files changed

+24
-18
lines changed

3 files changed

+24
-18
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'] }}:7000
24+
bind {{ hostvars[inventory_hostname]['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 %}
30-
bind {{ cluster_vip }}:5000
30+
bind {{ cluster_vip }}:{{ haproxy_listen_port.master }}
3131
{% else %}
32-
bind {{ hostvars[inventory_hostname]['inventory_hostname'] }}:5000
32+
bind {{ hostvars[inventory_hostname]['inventory_hostname'] }}:{{ haproxy_listen_port.master }}
3333
{% endif %}
3434
maxconn {{ haproxy_maxconn.master }}
3535
option tcplog
@@ -48,9 +48,9 @@ listen master
4848

4949
listen replicas
5050
{% if cluster_vip is defined and cluster_vip | length > 0 %}
51-
bind {{ cluster_vip }}:5001
51+
bind {{ cluster_vip }}:{{ haproxy_listen_port.replicas }}
5252
{% else %}
53-
bind {{ hostvars[inventory_hostname]['inventory_hostname'] }}:5001
53+
bind {{ hostvars[inventory_hostname]['inventory_hostname'] }}:{{ haproxy_listen_port.replicas }}
5454
{% endif %}
5555
maxconn {{ haproxy_maxconn.replica }}
5656
option tcplog
@@ -70,9 +70,9 @@ listen replicas
7070

7171
listen replicas_sync
7272
{% if cluster_vip is defined and cluster_vip | length > 0 %}
73-
bind {{ cluster_vip }}:5002
73+
bind {{ cluster_vip }}:{{ haproxy_listen_port.replicas_sync }}
7474
{% else %}
75-
bind {{ hostvars[inventory_hostname]['inventory_hostname'] }}:5002
75+
bind {{ hostvars[inventory_hostname]['inventory_hostname'] }}:{{ haproxy_listen_port.replicas_sync }}
7676
{% endif %}
7777
maxconn {{ haproxy_maxconn.replica }}
7878
option tcplog
@@ -92,9 +92,9 @@ listen replicas_sync
9292

9393
listen replicas_async
9494
{% if cluster_vip is defined and cluster_vip | length > 0 %}
95-
bind {{ cluster_vip }}:5003
95+
bind {{ cluster_vip }}:{{ haproxy_listen_port.replicas_async }}
9696
{% else %}
97-
bind {{ hostvars[inventory_hostname]['inventory_hostname'] }}:5003
97+
bind {{ hostvars[inventory_hostname]['inventory_hostname'] }}:{{ haproxy_listen_port.replicas_async }}
9898
{% endif %}
9999
maxconn {{ haproxy_maxconn.replica }}
100100
option tcplog

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'] }}:7000
24+
bind {{ hostvars[inventory_hostname]['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 %}
30-
bind {{ cluster_vip }}:5000
30+
bind {{ cluster_vip }}:{{ haproxy_listen_port.master }}
3131
{% else %}
32-
bind {{ hostvars[inventory_hostname]['inventory_hostname'] }}:5000
32+
bind {{ hostvars[inventory_hostname]['inventory_hostname'] }}:{{ haproxy_listen_port.master }}
3333
{% endif %}
3434
maxconn {{ haproxy_maxconn.master }}
3535
option tcplog
@@ -49,9 +49,9 @@ server {{ hostvars[host]['ansible_hostname'] }} {{ hostvars[host]['inventory_hos
4949

5050
listen replicas
5151
{% if cluster_vip is defined and cluster_vip | length > 0 %}
52-
bind {{ cluster_vip }}:5001
52+
bind {{ cluster_vip }}:{{ haproxy_listen_port.replicas }}
5353
{% else %}
54-
bind {{ hostvars[inventory_hostname]['inventory_hostname'] }}:5001
54+
bind {{ hostvars[inventory_hostname]['inventory_hostname'] }}:{{ haproxy_listen_port.replicas }}
5555
{% endif %}
5656
maxconn {{ haproxy_maxconn.replica }}
5757
option tcplog
@@ -72,9 +72,9 @@ server {{ hostvars[host]['ansible_hostname'] }} {{ hostvars[host]['inventory_hos
7272

7373
listen replicas_sync
7474
{% if cluster_vip is defined and cluster_vip | length > 0 %}
75-
bind {{ cluster_vip }}:5002
75+
bind {{ cluster_vip }}:{{ haproxy_listen_port.replicas_sync }}
7676
{% else %}
77-
bind {{ hostvars[inventory_hostname]['inventory_hostname'] }}:5002
77+
bind {{ hostvars[inventory_hostname]['inventory_hostname'] }}:{{ haproxy_listen_port.replicas_sync }}
7878
{% endif %}
7979
maxconn {{ haproxy_maxconn.replica }}
8080
option tcplog
@@ -95,9 +95,9 @@ server {{ hostvars[host]['ansible_hostname'] }} {{ hostvars[host]['inventory_hos
9595

9696
listen replicas_async
9797
{% if cluster_vip is defined and cluster_vip | length > 0 %}
98-
bind {{ cluster_vip }}:5003
98+
bind {{ cluster_vip }}:{{ haproxy_listen_port.replicas_async }}
9999
{% else %}
100-
bind {{ hostvars[inventory_hostname]['inventory_hostname'] }}:5003
100+
bind {{ hostvars[inventory_hostname]['inventory_hostname'] }}:{{ haproxy_listen_port.replicas_async }}
101101
{% endif %}
102102
maxconn {{ haproxy_maxconn.replica }}
103103
option tcplog

vars/main.yml

+6
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ synchronous_node_count: 1 # number of synchronous standby databases
2828

2929
# Load Balancing
3030
with_haproxy_load_balancing: false # or 'true' if you want to install and configure the load-balancing
31+
haproxy_listen_port:
32+
master: 5000
33+
replicas: 5001
34+
replicas_sync: 5002
35+
replicas_async: 5003
36+
stats: 7000
3137
haproxy_maxconn:
3238
global: 100000
3339
master: 10000

0 commit comments

Comments
 (0)