Skip to content

Commit

Permalink
haproxy: add haproxy_listen_port variables
Browse files Browse the repository at this point in the history
  • Loading branch information
vitabaks committed Sep 21, 2021
1 parent 0417a84 commit 7474ba3
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 18 deletions.
18 changes: 9 additions & 9 deletions roles/confd/templates/haproxy.tmpl.j2
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ defaults

listen stats
mode http
bind {{ hostvars[inventory_hostname]['inventory_hostname'] }}:7000
bind {{ hostvars[inventory_hostname]['inventory_hostname'] }}:{{ haproxy_listen_port.stats }}
stats enable
stats uri /

listen master
{% if cluster_vip is defined and cluster_vip | length > 0 %}
bind {{ cluster_vip }}:5000
bind {{ cluster_vip }}:{{ haproxy_listen_port.master }}
{% else %}
bind {{ hostvars[inventory_hostname]['inventory_hostname'] }}:5000
bind {{ hostvars[inventory_hostname]['inventory_hostname'] }}:{{ haproxy_listen_port.master }}
{% endif %}
maxconn {{ haproxy_maxconn.master }}
option tcplog
Expand All @@ -48,9 +48,9 @@ listen master

listen replicas
{% if cluster_vip is defined and cluster_vip | length > 0 %}
bind {{ cluster_vip }}:5001
bind {{ cluster_vip }}:{{ haproxy_listen_port.replicas }}
{% else %}
bind {{ hostvars[inventory_hostname]['inventory_hostname'] }}:5001
bind {{ hostvars[inventory_hostname]['inventory_hostname'] }}:{{ haproxy_listen_port.replicas }}
{% endif %}
maxconn {{ haproxy_maxconn.replica }}
option tcplog
Expand All @@ -70,9 +70,9 @@ listen replicas

listen replicas_sync
{% if cluster_vip is defined and cluster_vip | length > 0 %}
bind {{ cluster_vip }}:5002
bind {{ cluster_vip }}:{{ haproxy_listen_port.replicas_sync }}
{% else %}
bind {{ hostvars[inventory_hostname]['inventory_hostname'] }}:5002
bind {{ hostvars[inventory_hostname]['inventory_hostname'] }}:{{ haproxy_listen_port.replicas_sync }}
{% endif %}
maxconn {{ haproxy_maxconn.replica }}
option tcplog
Expand All @@ -92,9 +92,9 @@ listen replicas_sync

listen replicas_async
{% if cluster_vip is defined and cluster_vip | length > 0 %}
bind {{ cluster_vip }}:5003
bind {{ cluster_vip }}:{{ haproxy_listen_port.replicas_async }}
{% else %}
bind {{ hostvars[inventory_hostname]['inventory_hostname'] }}:5003
bind {{ hostvars[inventory_hostname]['inventory_hostname'] }}:{{ haproxy_listen_port.replicas_async }}
{% endif %}
maxconn {{ haproxy_maxconn.replica }}
option tcplog
Expand Down
18 changes: 9 additions & 9 deletions roles/haproxy/templates/haproxy.cfg.j2
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ defaults

listen stats
mode http
bind {{ hostvars[inventory_hostname]['inventory_hostname'] }}:7000
bind {{ hostvars[inventory_hostname]['inventory_hostname'] }}:{{ haproxy_listen_port.stats }}
stats enable
stats uri /

listen master
{% if cluster_vip is defined and cluster_vip | length > 0 %}
bind {{ cluster_vip }}:5000
bind {{ cluster_vip }}:{{ haproxy_listen_port.master }}
{% else %}
bind {{ hostvars[inventory_hostname]['inventory_hostname'] }}:5000
bind {{ hostvars[inventory_hostname]['inventory_hostname'] }}:{{ haproxy_listen_port.master }}
{% endif %}
maxconn {{ haproxy_maxconn.master }}
option tcplog
Expand All @@ -49,9 +49,9 @@ server {{ hostvars[host]['ansible_hostname'] }} {{ hostvars[host]['inventory_hos

listen replicas
{% if cluster_vip is defined and cluster_vip | length > 0 %}
bind {{ cluster_vip }}:5001
bind {{ cluster_vip }}:{{ haproxy_listen_port.replicas }}
{% else %}
bind {{ hostvars[inventory_hostname]['inventory_hostname'] }}:5001
bind {{ hostvars[inventory_hostname]['inventory_hostname'] }}:{{ haproxy_listen_port.replicas }}
{% endif %}
maxconn {{ haproxy_maxconn.replica }}
option tcplog
Expand All @@ -72,9 +72,9 @@ server {{ hostvars[host]['ansible_hostname'] }} {{ hostvars[host]['inventory_hos

listen replicas_sync
{% if cluster_vip is defined and cluster_vip | length > 0 %}
bind {{ cluster_vip }}:5002
bind {{ cluster_vip }}:{{ haproxy_listen_port.replicas_sync }}
{% else %}
bind {{ hostvars[inventory_hostname]['inventory_hostname'] }}:5002
bind {{ hostvars[inventory_hostname]['inventory_hostname'] }}:{{ haproxy_listen_port.replicas_sync }}
{% endif %}
maxconn {{ haproxy_maxconn.replica }}
option tcplog
Expand All @@ -95,9 +95,9 @@ server {{ hostvars[host]['ansible_hostname'] }} {{ hostvars[host]['inventory_hos

listen replicas_async
{% if cluster_vip is defined and cluster_vip | length > 0 %}
bind {{ cluster_vip }}:5003
bind {{ cluster_vip }}:{{ haproxy_listen_port.replicas_async }}
{% else %}
bind {{ hostvars[inventory_hostname]['inventory_hostname'] }}:5003
bind {{ hostvars[inventory_hostname]['inventory_hostname'] }}:{{ haproxy_listen_port.replicas_async }}
{% endif %}
maxconn {{ haproxy_maxconn.replica }}
option tcplog
Expand Down
6 changes: 6 additions & 0 deletions vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ synchronous_node_count: 1 # number of synchronous standby databases

# Load Balancing
with_haproxy_load_balancing: false # or 'true' if you want to install and configure the load-balancing
haproxy_listen_port:
master: 5000
replicas: 5001
replicas_sync: 5002
replicas_async: 5003
stats: 7000
haproxy_maxconn:
global: 100000
master: 10000
Expand Down

0 comments on commit 7474ba3

Please sign in to comment.