Skip to content

Commit

Permalink
Add patroni_restapi_listen_addr and postgresql_listen_addr variables (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
vitabaks authored Mar 12, 2024
1 parent 80901cc commit a46714e
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 48 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'] }}:{{ haproxy_listen_port.stats }}
bind {{ 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 }}:{{ haproxy_listen_port.master }}
{% else %}
bind {{ hostvars[inventory_hostname]['inventory_hostname'] }}:{{ haproxy_listen_port.master }}
bind {{ inventory_hostname }}:{{ haproxy_listen_port.master }}
{% endif %}
maxconn {{ haproxy_maxconn.master }}
option tcplog
Expand All @@ -50,7 +50,7 @@ listen master_direct
{% if cluster_vip is defined and cluster_vip | length > 0 %}
bind {{ cluster_vip }}:{{ haproxy_listen_port.master_direct }}
{% else %}
bind {{ hostvars[inventory_hostname]['inventory_hostname'] }}:{{ haproxy_listen_port.master_direct }}
bind {{ inventory_hostname }}:{{ haproxy_listen_port.master_direct }}
{% endif %}
maxconn {{ haproxy_maxconn.master }}
option tcplog
Expand All @@ -65,7 +65,7 @@ listen replicas
{% if cluster_vip is defined and cluster_vip | length > 0 %}
bind {{ cluster_vip }}:{{ haproxy_listen_port.replicas }}
{% else %}
bind {{ hostvars[inventory_hostname]['inventory_hostname'] }}:{{ haproxy_listen_port.replicas }}
bind {{ inventory_hostname }}:{{ haproxy_listen_port.replicas }}
{% endif %}
maxconn {{ haproxy_maxconn.replica }}
option tcplog
Expand All @@ -87,7 +87,7 @@ listen replicas_direct
{% if cluster_vip is defined and cluster_vip | length > 0 %}
bind {{ cluster_vip }}:{{ haproxy_listen_port.replicas_direct }}
{% else %}
bind {{ hostvars[inventory_hostname]['inventory_hostname'] }}:{{ haproxy_listen_port.replicas_direct }}
bind {{ inventory_hostname }}:{{ haproxy_listen_port.replicas_direct }}
{% endif %}
maxconn {{ haproxy_maxconn.replica }}
option tcplog
Expand All @@ -103,7 +103,7 @@ listen replicas_sync
{% if cluster_vip is defined and cluster_vip | length > 0 %}
bind {{ cluster_vip }}:{{ haproxy_listen_port.replicas_sync }}
{% else %}
bind {{ hostvars[inventory_hostname]['inventory_hostname'] }}:{{ haproxy_listen_port.replicas_sync }}
bind {{ inventory_hostname }}:{{ haproxy_listen_port.replicas_sync }}
{% endif %}
maxconn {{ haproxy_maxconn.replica }}
option tcplog
Expand All @@ -125,7 +125,7 @@ listen replicas_sync_direct
{% if cluster_vip is defined and cluster_vip | length > 0 %}
bind {{ cluster_vip }}:{{ haproxy_listen_port.replicas_sync_direct }}
{% else %}
bind {{ hostvars[inventory_hostname]['inventory_hostname'] }}:{{ haproxy_listen_port.replicas_sync_direct }}
bind {{ inventory_hostname }}:{{ haproxy_listen_port.replicas_sync_direct }}
{% endif %}
maxconn {{ haproxy_maxconn.replica }}
option tcplog
Expand All @@ -141,7 +141,7 @@ listen replicas_async
{% if cluster_vip is defined and cluster_vip | length > 0 %}
bind {{ cluster_vip }}:{{ haproxy_listen_port.replicas_async }}
{% else %}
bind {{ hostvars[inventory_hostname]['inventory_hostname'] }}:{{ haproxy_listen_port.replicas_async }}
bind {{ inventory_hostname }}:{{ haproxy_listen_port.replicas_async }}
{% endif %}
maxconn {{ haproxy_maxconn.replica }}
option tcplog
Expand All @@ -163,7 +163,7 @@ listen replicas_async_direct
{% if cluster_vip is defined and cluster_vip | length > 0 %}
bind {{ cluster_vip }}:{{ haproxy_listen_port.replicas_async_direct }}
{% else %}
bind {{ hostvars[inventory_hostname]['inventory_hostname'] }}:{{ haproxy_listen_port.replicas_async_direct }}
bind {{ inventory_hostname }}:{{ haproxy_listen_port.replicas_async_direct }}
{% endif %}
maxconn {{ haproxy_maxconn.replica }}
option tcplog
Expand Down
2 changes: 1 addition & 1 deletion roles/haproxy/handlers/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
- name: Check HAProxy is started and accepting connections
ansible.builtin.wait_for:
port: "{{ haproxy_listen_port.stats }}"
host: "{{ hostvars[inventory_hostname]['inventory_hostname'] }}"
host: "{{ inventory_hostname }}"
state: started
timeout: 120
delay: 10
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'] }}:{{ haproxy_listen_port.stats }}
bind {{ 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 }}:{{ haproxy_listen_port.master }}
{% else %}
bind {{ hostvars[inventory_hostname]['inventory_hostname'] }}:{{ haproxy_listen_port.master }}
bind {{ inventory_hostname }}:{{ haproxy_listen_port.master }}
{% endif %}
maxconn {{ haproxy_maxconn.master }}
option tcplog
Expand All @@ -52,7 +52,7 @@ listen master_direct
{% if cluster_vip is defined and cluster_vip | length > 0 %}
bind {{ cluster_vip }}:{{ haproxy_listen_port.master_direct }}
{% else %}
bind {{ hostvars[inventory_hostname]['inventory_hostname'] }}:{{ haproxy_listen_port.master_direct }}
bind {{ inventory_hostname }}:{{ haproxy_listen_port.master_direct }}
{% endif %}
maxconn {{ haproxy_maxconn.master }}
option tcplog
Expand All @@ -68,7 +68,7 @@ listen replicas
{% if cluster_vip is defined and cluster_vip | length > 0 %}
bind {{ cluster_vip }}:{{ haproxy_listen_port.replicas }}
{% else %}
bind {{ hostvars[inventory_hostname]['inventory_hostname'] }}:{{ haproxy_listen_port.replicas }}
bind {{ inventory_hostname }}:{{ haproxy_listen_port.replicas }}
{% endif %}
maxconn {{ haproxy_maxconn.replica }}
option tcplog
Expand All @@ -92,7 +92,7 @@ listen replicas_direct
{% if cluster_vip is defined and cluster_vip | length > 0 %}
bind {{ cluster_vip }}:{{ haproxy_listen_port.replicas_direct }}
{% else %}
bind {{ hostvars[inventory_hostname]['inventory_hostname'] }}:{{ haproxy_listen_port.replicas_direct }}
bind {{ inventory_hostname }}:{{ haproxy_listen_port.replicas_direct }}
{% endif %}
maxconn {{ haproxy_maxconn.replica }}
option tcplog
Expand All @@ -109,7 +109,7 @@ listen replicas_sync
{% if cluster_vip is defined and cluster_vip | length > 0 %}
bind {{ cluster_vip }}:{{ haproxy_listen_port.replicas_sync }}
{% else %}
bind {{ hostvars[inventory_hostname]['inventory_hostname'] }}:{{ haproxy_listen_port.replicas_sync }}
bind {{ inventory_hostname }}:{{ haproxy_listen_port.replicas_sync }}
{% endif %}
maxconn {{ haproxy_maxconn.replica }}
option tcplog
Expand All @@ -133,7 +133,7 @@ listen replicas_sync_direct
{% if cluster_vip is defined and cluster_vip | length > 0 %}
bind {{ cluster_vip }}:{{ haproxy_listen_port.replicas_sync_direct }}
{% else %}
bind {{ hostvars[inventory_hostname]['inventory_hostname'] }}:{{ haproxy_listen_port.replicas_sync_direct }}
bind {{ inventory_hostname }}:{{ haproxy_listen_port.replicas_sync_direct }}
{% endif %}
maxconn {{ haproxy_maxconn.replica }}
option tcplog
Expand All @@ -150,7 +150,7 @@ listen replicas_async
{% if cluster_vip is defined and cluster_vip | length > 0 %}
bind {{ cluster_vip }}:{{ haproxy_listen_port.replicas_async }}
{% else %}
bind {{ hostvars[inventory_hostname]['inventory_hostname'] }}:{{ haproxy_listen_port.replicas_async }}
bind {{ inventory_hostname }}:{{ haproxy_listen_port.replicas_async }}
{% endif %}
maxconn {{ haproxy_maxconn.replica }}
option tcplog
Expand All @@ -174,7 +174,7 @@ listen replicas_async_direct
{% if cluster_vip is defined and cluster_vip | length > 0 %}
bind {{ cluster_vip }}:{{ haproxy_listen_port.replicas_async_direct }}
{% else %}
bind {{ hostvars[inventory_hostname]['inventory_hostname'] }}:{{ haproxy_listen_port.replicas_async_direct }}
bind {{ inventory_hostname }}:{{ haproxy_listen_port.replicas_async_direct }}
{% endif %}
maxconn {{ haproxy_maxconn.replica }}
option tcplog
Expand Down
4 changes: 2 additions & 2 deletions roles/patroni/config/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
- block:
- name: Update postgresql parameters in DCS
ansible.builtin.uri:
url: http://{{ hostvars[inventory_hostname]['inventory_hostname'] }}:{{ patroni_restapi_port }}/config
url: http://{{ inventory_hostname }}:{{ patroni_restapi_port }}/config
method: PATCH
body: '{"postgresql":{"parameters":{"{{ item.option }}":"{{ item.value }}"}}}'
body_format: json
Expand All @@ -51,7 +51,7 @@

- name: Delete postgresql parameters from DCS
ansible.builtin.uri:
url: http://{{ hostvars[inventory_hostname]['inventory_hostname'] }}:{{ patroni_restapi_port }}/config
url: http://{{ inventory_hostname }}:{{ patroni_restapi_port }}/config
method: PATCH
body: '{"postgresql":{"parameters":{"{{ item.option }}":null}}}'
body_format: json
Expand Down
8 changes: 4 additions & 4 deletions roles/patroni/tasks/custom_wal_dir.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
- name: "Wait for port {{ patroni_restapi_port }} to become open on the host"
ansible.builtin.wait_for:
port: "{{ patroni_restapi_port }}"
host: "{{ hostvars[inventory_hostname]['inventory_hostname'] }}"
host: "{{ inventory_hostname }}"
state: started
timeout: 120
delay: 10
Expand All @@ -107,7 +107,7 @@

- name: Check that the patroni is healthy (the leader with the lock)
ansible.builtin.uri:
url: "http://{{ hostvars[inventory_hostname]['inventory_hostname'] }}:{{ patroni_restapi_port }}/leader"
url: "http://{{ inventory_hostname }}:{{ patroni_restapi_port }}/leader"
status_code: 200
register: patroni_result
until: patroni_result.status == 200
Expand All @@ -128,7 +128,7 @@
- name: "Wait for port {{ patroni_restapi_port }} to become open on the host"
ansible.builtin.wait_for:
port: "{{ patroni_restapi_port }}"
host: "{{ hostvars[inventory_hostname]['inventory_hostname'] }}"
host: "{{ inventory_hostname }}"
state: started
timeout: 120
delay: 10
Expand All @@ -137,7 +137,7 @@

- name: Check that the patroni is healthy on the Replica
ansible.builtin.uri:
url: "http://{{ hostvars[inventory_hostname]['inventory_hostname'] }}:{{ patroni_restapi_port }}/health"
url: "http://{{ inventory_hostname }}:{{ patroni_restapi_port }}/health"
status_code: 200
register: patroni_result
until: patroni_result.status == 200
Expand Down
8 changes: 4 additions & 4 deletions roles/patroni/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@
- name: "Wait for port {{ patroni_restapi_port }} to become open on the host"
ansible.builtin.wait_for:
port: "{{ patroni_restapi_port }}"
host: "{{ hostvars[inventory_hostname]['inventory_hostname'] }}"
host: "{{ inventory_hostname }}"
state: started
timeout: 120
delay: 10
Expand Down Expand Up @@ -813,7 +813,7 @@

- name: Wait for the cluster to initialize (master is the leader with the lock)
ansible.builtin.uri:
url: "http://{{ hostvars[inventory_hostname]['inventory_hostname'] }}:{{ patroni_restapi_port }}/leader"
url: "http://{{ inventory_hostname }}:{{ patroni_restapi_port }}/leader"
status_code: 200
register: result
until: result.status == 200
Expand Down Expand Up @@ -955,15 +955,15 @@
- name: "Wait for port {{ patroni_restapi_port }} to become open on the host"
ansible.builtin.wait_for:
port: "{{ patroni_restapi_port }}"
host: "{{ hostvars[inventory_hostname]['inventory_hostname'] }}"
host: "{{ inventory_hostname }}"
state: started
timeout: 120
delay: 10
ignore_errors: false

- name: Check that the patroni is healthy on the replica server
ansible.builtin.uri:
url: "http://{{ hostvars[inventory_hostname]['inventory_hostname'] }}:{{ patroni_restapi_port }}/health"
url: "http://{{ inventory_hostname }}:{{ patroni_restapi_port }}/health"
status_code: 200
register: replica_result
until: replica_result.status == 200
Expand Down
12 changes: 4 additions & 8 deletions roles/patroni/templates/patroni.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ log:
{% endif %}

restapi:
listen: {{ hostvars[inventory_hostname]['inventory_hostname'] }}:{{ patroni_restapi_port }}
connect_address: {{ hostvars[inventory_hostname]['inventory_hostname'] }}:{{ patroni_restapi_port }}
listen: {{ patroni_restapi_listen_addr }}:{{ patroni_restapi_port }}
connect_address: {{ inventory_hostname }}:{{ patroni_restapi_port }}
# certfile: /etc/ssl/certs/ssl-cert-snakeoil.pem
# keyfile: /etc/ssl/private/ssl-cert-snakeoil.key
# authentication:
Expand Down Expand Up @@ -121,12 +121,8 @@ bootstrap:


postgresql:
{% if not with_haproxy_load_balancing|bool and not pgbouncer_install|bool and (cluster_vip is defined and cluster_vip | length > 0) %}
listen: {{ hostvars[inventory_hostname]['inventory_hostname'] }},{{ cluster_vip }},127.0.0.1:{{ postgresql_port }}
{% else %}
listen: {{ hostvars[inventory_hostname]['inventory_hostname'] }},127.0.0.1:{{ postgresql_port }}
{% endif %}
connect_address: {{ hostvars[inventory_hostname]['inventory_hostname'] }}:{{ postgresql_port }}
listen: {{ postgresql_listen_addr }}:{{ postgresql_port }}
connect_address: {{ inventory_hostname }}:{{ postgresql_port }}
{% if patroni_superuser_username == 'postgres' %}
use_unix_socket: true
{% endif %}
Expand Down
2 changes: 1 addition & 1 deletion roles/pgbouncer/handlers/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
- name: Wait for port "{{ pgbouncer_listen_port }}" to become open on the host
ansible.builtin.wait_for:
port: "{{ pgbouncer_listen_port }}"
host: "{{ hostvars[inventory_hostname]['inventory_hostname'] }}"
host: "{{ inventory_hostname }}"
state: started
timeout: 120
delay: 5
Expand Down
18 changes: 9 additions & 9 deletions roles/upgrade/templates/haproxy-no-http-checks.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'] }}:{{ haproxy_listen_port.stats }}
bind {{ 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 }}:{{ haproxy_listen_port.master }}
{% else %}
bind {{ hostvars[inventory_hostname]['inventory_hostname'] }}:{{ haproxy_listen_port.master }}
bind {{ inventory_hostname }}:{{ haproxy_listen_port.master }}
{% endif %}
maxconn {{ haproxy_maxconn.master }}
option tcplog
Expand All @@ -42,7 +42,7 @@ listen master_direct
{% if cluster_vip is defined and cluster_vip | length > 0 %}
bind {{ cluster_vip }}:{{ haproxy_listen_port.master_direct }}
{% else %}
bind {{ hostvars[inventory_hostname]['inventory_hostname'] }}:{{ haproxy_listen_port.master_direct }}
bind {{ inventory_hostname }}:{{ haproxy_listen_port.master_direct }}
{% endif %}
maxconn {{ haproxy_maxconn.master }}
option tcplog
Expand All @@ -55,7 +55,7 @@ listen replicas
{% if cluster_vip is defined and cluster_vip | length > 0 %}
bind {{ cluster_vip }}:{{ haproxy_listen_port.replicas }}
{% else %}
bind {{ hostvars[inventory_hostname]['inventory_hostname'] }}:{{ haproxy_listen_port.replicas }}
bind {{ inventory_hostname }}:{{ haproxy_listen_port.replicas }}
{% endif %}
maxconn {{ haproxy_maxconn.replica }}
option tcplog
Expand All @@ -69,7 +69,7 @@ listen replicas_direct
{% if cluster_vip is defined and cluster_vip | length > 0 %}
bind {{ cluster_vip }}:{{ haproxy_listen_port.replicas_direct }}
{% else %}
bind {{ hostvars[inventory_hostname]['inventory_hostname'] }}:{{ haproxy_listen_port.replicas_direct }}
bind {{ inventory_hostname }}:{{ haproxy_listen_port.replicas_direct }}
{% endif %}
maxconn {{ haproxy_maxconn.replica }}
option tcplog
Expand All @@ -83,7 +83,7 @@ listen replicas_sync
{% if cluster_vip is defined and cluster_vip | length > 0 %}
bind {{ cluster_vip }}:{{ haproxy_listen_port.replicas_sync }}
{% else %}
bind {{ hostvars[inventory_hostname]['inventory_hostname'] }}:{{ haproxy_listen_port.replicas_sync }}
bind {{ inventory_hostname }}:{{ haproxy_listen_port.replicas_sync }}
{% endif %}
maxconn {{ haproxy_maxconn.replica }}
option tcplog
Expand All @@ -97,7 +97,7 @@ listen replicas_sync_direct
{% if cluster_vip is defined and cluster_vip | length > 0 %}
bind {{ cluster_vip }}:{{ haproxy_listen_port.replicas_sync_direct }}
{% else %}
bind {{ hostvars[inventory_hostname]['inventory_hostname'] }}:{{ haproxy_listen_port.replicas_sync_direct }}
bind {{ inventory_hostname }}:{{ haproxy_listen_port.replicas_sync_direct }}
{% endif %}
maxconn {{ haproxy_maxconn.replica }}
option tcplog
Expand All @@ -111,7 +111,7 @@ listen replicas_async
{% if cluster_vip is defined and cluster_vip | length > 0 %}
bind {{ cluster_vip }}:{{ haproxy_listen_port.replicas_async }}
{% else %}
bind {{ hostvars[inventory_hostname]['inventory_hostname'] }}:{{ haproxy_listen_port.replicas_async }}
bind {{ inventory_hostname }}:{{ haproxy_listen_port.replicas_async }}
{% endif %}
maxconn {{ haproxy_maxconn.replica }}
option tcplog
Expand All @@ -125,7 +125,7 @@ listen replicas_async_direct
{% if cluster_vip is defined and cluster_vip | length > 0 %}
bind {{ cluster_vip }}:{{ haproxy_listen_port.replicas_async_direct }}
{% else %}
bind {{ hostvars[inventory_hostname]['inventory_hostname'] }}:{{ haproxy_listen_port.replicas_async_direct }}
bind {{ inventory_hostname }}:{{ haproxy_listen_port.replicas_async_direct }}
{% endif %}
maxconn {{ haproxy_maxconn.replica }}
option tcplog
Expand Down
Loading

0 comments on commit a46714e

Please sign in to comment.