Skip to content

Commit 2bdabdc

Browse files
authored
Add patroni_restapi_port variable (vitabaks#279)
1 parent eb35ebc commit 2bdabdc

File tree

7 files changed

+36
-35
lines changed

7 files changed

+36
-35
lines changed

roles/haproxy/templates/haproxy.cfg.j2

+8-8
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ listen master
3838
default-server inter 3s fastinter 1s fall 3 rise 4 on-marked-down shutdown-sessions
3939
{% if pgbouncer_install|bool %}
4040
{% for host in groups['postgres_cluster'] %}
41-
server {{ hostvars[host]['ansible_hostname'] }} {{ hostvars[host]['inventory_hostname'] }}:{{ pgbouncer_listen_port }} check port 8008
41+
server {{ hostvars[host]['ansible_hostname'] }} {{ hostvars[host]['inventory_hostname'] }}:{{ pgbouncer_listen_port }} check port {{ patroni_restapi_port }}
4242
{% endfor %}
4343
{% endif %}
4444
{% if ( pgbouncer_install is not defined ) or ( not pgbouncer_install|bool ) %}
4545
{% for host in groups['postgres_cluster'] %}
46-
server {{ hostvars[host]['ansible_hostname'] }} {{ hostvars[host]['inventory_hostname'] }}:{{ postgresql_port }} check port 8008
46+
server {{ hostvars[host]['ansible_hostname'] }} {{ hostvars[host]['inventory_hostname'] }}:{{ postgresql_port }} check port {{ patroni_restapi_port }}
4747
{% endfor %}
4848
{% endif %}
4949

@@ -61,12 +61,12 @@ listen replicas
6161
default-server inter 3s fastinter 1s fall 3 rise 2 on-marked-down shutdown-sessions
6262
{% if pgbouncer_install|bool %}
6363
{% for host in groups['postgres_cluster'] %}
64-
server {{ hostvars[host]['ansible_hostname'] }} {{ hostvars[host]['inventory_hostname'] }}:{{ pgbouncer_listen_port }} check port 8008
64+
server {{ hostvars[host]['ansible_hostname'] }} {{ hostvars[host]['inventory_hostname'] }}:{{ pgbouncer_listen_port }} check port {{ patroni_restapi_port }}
6565
{% endfor %}
6666
{% endif %}
6767
{% if ( pgbouncer_install is not defined ) or ( not pgbouncer_install|bool ) %}
6868
{% for host in groups['postgres_cluster'] %}
69-
server {{ hostvars[host]['ansible_hostname'] }} {{ hostvars[host]['inventory_hostname'] }}:{{ postgresql_port }} check port 8008
69+
server {{ hostvars[host]['ansible_hostname'] }} {{ hostvars[host]['inventory_hostname'] }}:{{ postgresql_port }} check port {{ patroni_restapi_port }}
7070
{% endfor %}
7171
{% endif %}
7272

@@ -84,12 +84,12 @@ listen replicas_sync
8484
default-server inter 3s fastinter 1s fall 3 rise 2 on-marked-down shutdown-sessions
8585
{% if pgbouncer_install|bool %}
8686
{% for host in groups['postgres_cluster'] %}
87-
server {{ hostvars[host]['ansible_hostname'] }} {{ hostvars[host]['inventory_hostname'] }}:{{ pgbouncer_listen_port }} check port 8008
87+
server {{ hostvars[host]['ansible_hostname'] }} {{ hostvars[host]['inventory_hostname'] }}:{{ pgbouncer_listen_port }} check port {{ patroni_restapi_port }}
8888
{% endfor %}
8989
{% endif %}
9090
{% if ( pgbouncer_install is not defined ) or ( not pgbouncer_install|bool ) %}
9191
{% for host in groups['postgres_cluster'] %}
92-
server {{ hostvars[host]['ansible_hostname'] }} {{ hostvars[host]['inventory_hostname'] }}:{{ postgresql_port }} check port 8008
92+
server {{ hostvars[host]['ansible_hostname'] }} {{ hostvars[host]['inventory_hostname'] }}:{{ postgresql_port }} check port {{ patroni_restapi_port }}
9393
{% endfor %}
9494
{% endif %}
9595

@@ -107,12 +107,12 @@ listen replicas_async
107107
default-server inter 3s fastinter 1s fall 3 rise 2 on-marked-down shutdown-sessions
108108
{% if pgbouncer_install|bool %}
109109
{% for host in groups['postgres_cluster'] %}
110-
server {{ hostvars[host]['ansible_hostname'] }} {{ hostvars[host]['inventory_hostname'] }}:{{ pgbouncer_listen_port }} check port 8008
110+
server {{ hostvars[host]['ansible_hostname'] }} {{ hostvars[host]['inventory_hostname'] }}:{{ pgbouncer_listen_port }} check port {{ patroni_restapi_port }}
111111
{% endfor %}
112112
{% endif %}
113113
{% if ( pgbouncer_install is not defined ) or ( not pgbouncer_install|bool ) %}
114114
{% for host in groups['postgres_cluster'] %}
115-
server {{ hostvars[host]['ansible_hostname'] }} {{ hostvars[host]['inventory_hostname'] }}:{{ postgresql_port }} check port 8008
115+
server {{ hostvars[host]['ansible_hostname'] }} {{ hostvars[host]['inventory_hostname'] }}:{{ postgresql_port }} check port {{ patroni_restapi_port }}
116116
{% endfor %}
117117
{% endif %}
118118

roles/patroni/config/tasks/main.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
- block:
5353
- name: Update postgresql parameters in DCS
5454
uri:
55-
url: http://{{ hostvars[inventory_hostname]['inventory_hostname'] }}:8008/config
55+
url: http://{{ hostvars[inventory_hostname]['inventory_hostname'] }}:{{ patroni_restapi_port }}/config
5656
method: PATCH
5757
body: '{"postgresql":{"parameters":{"{{ item.option }}":"{{ item.value }}"}}}'
5858
body_format: json
@@ -61,7 +61,7 @@
6161

6262
- name: Delete postgresql parameters from DCS
6363
uri:
64-
url: http://{{ hostvars[inventory_hostname]['inventory_hostname'] }}:8008/config
64+
url: http://{{ hostvars[inventory_hostname]['inventory_hostname'] }}:{{ patroni_restapi_port }}/config
6565
method: PATCH
6666
body: '{"postgresql":{"parameters":{"{{ item.option }}":null}}}'
6767
body_format: json

roles/patroni/tasks/custom_wal_dir.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@
5959
name: patroni
6060
state: started
6161

62-
- name: Wait for port 8008 to become open on the host
62+
- name: "Wait for port {{ patroni_restapi_port }} to become open on the host"
6363
wait_for:
64-
port: 8008
64+
port: "{{ patroni_restapi_port }}"
6565
host: "{{ hostvars[inventory_hostname]['inventory_hostname'] }}"
6666
state: started
6767
timeout: 120
@@ -70,7 +70,7 @@
7070

7171
- name: Check that the patroni is healthy
7272
uri:
73-
url: "http://{{ hostvars[inventory_hostname]['inventory_hostname'] }}:8008/health"
73+
url: "http://{{ hostvars[inventory_hostname]['inventory_hostname'] }}:{{ patroni_restapi_port }}/health"
7474
status_code: 200
7575
register: replica_result
7676
until: replica_result.status == 200

roles/patroni/tasks/main.yml

+14-14
Original file line numberDiff line numberDiff line change
@@ -299,10 +299,10 @@
299299
backrefs: true
300300
loop:
301301
- { regexp: '^name:', line: 'name: {{ ansible_hostname }}' }
302-
- { regexp: '^ listen: .*:8008$', line: ' listen: {{ hostvars[inventory_hostname].inventory_hostname }}:8008' }
303-
- { regexp: '^ connect_address: .*:8008$', line: ' connect_address: {{ hostvars[inventory_hostname].inventory_hostname }}:8008' }
304-
- { regexp: '^ listen: ((?!8008).)*$', line: ' listen: {{ hostvars[inventory_hostname].inventory_hostname }},127.0.0.1:{{ postgresql_port }}' }
305-
- { regexp: '^ connect_address: ((?!8008).)*$', line: ' connect_address: {{ hostvars[inventory_hostname].inventory_hostname }}:{{ postgresql_port }}' }
302+
- { regexp: '^ listen: .*:{{ patroni_restapi_port }}$', line: ' listen: {{ hostvars[inventory_hostname].inventory_hostname }}:{{ patroni_restapi_port }}' }
303+
- { regexp: '^ connect_address: .*:{{ patroni_restapi_port }}$', line: ' connect_address: {{ hostvars[inventory_hostname].inventory_hostname }}:{{ patroni_restapi_port }}' }
304+
- { regexp: '^ listen: ((?!{{ patroni_restapi_port }}).)*$', line: ' listen: {{ hostvars[inventory_hostname].inventory_hostname }},127.0.0.1:{{ postgresql_port }}' }
305+
- { regexp: '^ connect_address: ((?!{{ patroni_restapi_port }}).)*$', line: ' connect_address: {{ hostvars[inventory_hostname].inventory_hostname }}:{{ postgresql_port }}' }
306306
loop_control:
307307
label: "{{ item.line }}"
308308
when: with_haproxy_load_balancing|bool or pgbouncer_install|bool or (cluster_vip is not defined or cluster_vip | length < 1)
@@ -315,10 +315,10 @@
315315
backrefs: true
316316
loop:
317317
- { regexp: '^name:', line: 'name: {{ ansible_hostname }}' }
318-
- { regexp: '^ listen: .*:8008$', line: ' listen: {{ hostvars[inventory_hostname].inventory_hostname }}:8008' }
319-
- { regexp: '^ connect_address: .*:8008$', line: ' connect_address: {{ hostvars[inventory_hostname].inventory_hostname }}:8008' }
320-
- { regexp: '^ listen: ((?!8008).)*$', line: ' listen: {{ hostvars[inventory_hostname].inventory_hostname }},{{ cluster_vip }},127.0.0.1:{{ postgresql_port }}' }
321-
- { regexp: '^ connect_address: ((?!8008).)*$', line: ' connect_address: {{ hostvars[inventory_hostname].inventory_hostname }}:{{ postgresql_port }}' }
318+
- { regexp: '^ listen: .*:{{ patroni_restapi_port }}$', line: ' listen: {{ hostvars[inventory_hostname].inventory_hostname }}:{{ patroni_restapi_port }}' }
319+
- { regexp: '^ connect_address: .*:{{ patroni_restapi_port }}$', line: ' connect_address: {{ hostvars[inventory_hostname].inventory_hostname }}:{{ patroni_restapi_port }}' }
320+
- { regexp: '^ listen: ((?!{{ patroni_restapi_port }}).)*$', line: ' listen: {{ hostvars[inventory_hostname].inventory_hostname }},{{ cluster_vip }},127.0.0.1:{{ postgresql_port }}' }
321+
- { regexp: '^ connect_address: ((?!{{ patroni_restapi_port }}).)*$', line: ' connect_address: {{ hostvars[inventory_hostname].inventory_hostname }}:{{ postgresql_port }}' }
322322
loop_control:
323323
label: "{{ item.line }}"
324324
when: not with_haproxy_load_balancing|bool and not pgbouncer_install|bool and (cluster_vip is defined and cluster_vip | length > 0)
@@ -779,9 +779,9 @@
779779
state: restarted
780780
enabled: true
781781

782-
- name: Wait for port 8008 to become open on the host
782+
- name: "Wait for port {{ patroni_restapi_port }} to become open on the host"
783783
wait_for:
784-
port: 8008
784+
port: "{{ patroni_restapi_port }}"
785785
host: "{{ hostvars[inventory_hostname]['inventory_hostname'] }}"
786786
state: started
787787
timeout: 120
@@ -813,7 +813,7 @@
813813

814814
- name: Wait for the cluster to initialize (master is the leader with the lock)
815815
uri:
816-
url: "http://{{ hostvars[inventory_hostname]['inventory_hostname'] }}:8008/leader"
816+
url: "http://{{ hostvars[inventory_hostname]['inventory_hostname'] }}:{{ patroni_restapi_port }}/leader"
817817
status_code: 200
818818
register: result
819819
until: result.status == 200
@@ -946,9 +946,9 @@
946946
state: restarted
947947
enabled: true
948948

949-
- name: Wait for port 8008 to become open on the host
949+
- name: "Wait for port {{ patroni_restapi_port }} to become open on the host"
950950
wait_for:
951-
port: 8008
951+
port: "{{ patroni_restapi_port }}"
952952
host: "{{ hostvars[inventory_hostname]['inventory_hostname'] }}"
953953
state: started
954954
timeout: 120
@@ -957,7 +957,7 @@
957957

958958
- name: Check that the patroni is healthy on the replica server
959959
uri:
960-
url: "http://{{ hostvars[inventory_hostname]['inventory_hostname'] }}:8008/health"
960+
url: "http://{{ hostvars[inventory_hostname]['inventory_hostname'] }}:{{ patroni_restapi_port }}/health"
961961
status_code: 200
962962
register: replica_result
963963
until: replica_result.status == 200

roles/patroni/templates/patroni.yml.j2

+2-2
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'] }}:8008
25-
connect_address: {{ hostvars[inventory_hostname]['inventory_hostname'] }}:8008
24+
listen: {{ hostvars[inventory_hostname]['inventory_hostname'] }}:{{ patroni_restapi_port }}
25+
connect_address: {{ hostvars[inventory_hostname]['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:

vars/main.yml

+6-5
Original file line numberDiff line numberDiff line change
@@ -104,28 +104,28 @@ consul_services:
104104
tags: ['master']
105105
port: "{{ pgbouncer_listen_port }}" # or "{{ postgresql_port }}" if pgbouncer_install: false
106106
checks:
107-
- { http: "http://{{ inventory_hostname }}:8008/master", interval: "2s" }
107+
- { http: "http://{{ inventory_hostname }}:{{ patroni_restapi_port }}/master", interval: "2s" }
108108
- { args: ["systemctl", "status", "pgbouncer"], interval: "5s" } # comment out this check if pgbouncer_install: false
109109
- name: "{{ patroni_cluster_name }}"
110110
id: "{{ patroni_cluster_name }}-replica"
111111
tags: ['replica']
112112
port: "{{ pgbouncer_listen_port }}"
113113
checks:
114-
- { http: "http://{{ inventory_hostname }}:8008/replica", interval: "2s" }
114+
- { http: "http://{{ inventory_hostname }}:{{ patroni_restapi_port }}/replica", interval: "2s" }
115115
- { args: ["systemctl", "status", "pgbouncer"], interval: "5s" }
116116
# - name: "{{ patroni_cluster_name }}"
117117
# id: "{{ patroni_cluster_name }}-sync-replica"
118118
# tags: ['sync-replica']
119119
# port: "{{ pgbouncer_listen_port }}"
120120
# checks:
121-
# - { http: "http://{{ inventory_hostname }}:8008/sync", interval: "2s" }
121+
# - { http: "http://{{ inventory_hostname }}:{{ patroni_restapi_port }}/sync", interval: "2s" }
122122
# - { args: ["systemctl", "status", "pgbouncer"], interval: "5s" }
123123
# - name: "{{ patroni_cluster_name }}"
124124
# id: "{{ patroni_cluster_name }}-async-replica"
125125
# tags: ['async-replica']
126126
# port: "{{ pgbouncer_listen_port }}"
127127
# checks:
128-
# - { http: "http://{{ inventory_hostname }}:8008/async", interval: "2s" }
128+
# - { http: "http://{{ inventory_hostname }}:{{ patroni_restapi_port }}/async", interval: "2s" }
129129
# - { args: ["systemctl", "status", "pgbouncer"], interval: "5s" }
130130

131131

@@ -295,6 +295,7 @@ pgbouncer_pools:
295295

296296

297297
# Extended variables (optional)
298+
patroni_restapi_port: 8008
298299
patroni_ttl: 30
299300
patroni_loop_wait: 10
300301
patroni_retry_timeout: 10
@@ -464,7 +465,7 @@ cron_jobs: []
464465
# day: "*"
465466
# month: "*"
466467
# weekday: "*"
467-
# job: "[ $(curl -s -o /dev/null -w '%{http_code}' http://{{ inventory_hostname }}:8008) = '200' ] && wal-g backup-push"
468+
# job: "[ $(curl -s -o /dev/null -w '%{http_code}' http://{{ inventory_hostname }}:{{ patroni_restapi_port }}) = '200' ] && wal-g backup-push"
468469

469470
# PITR mode (if patroni_cluster_bootstrap_method: "pgbackrest" or "wal-g"):
470471
# 1) The database cluster directory will be cleaned (for "wal-g") or overwritten (for "pgbackrest" --delta restore).

vars/system.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ firewall_allowed_tcp_ports_for:
134134
- "{{ ansible_ssh_port | default(22) }}"
135135
- "{{ postgresql_port }}"
136136
- "{{ pgbouncer_listen_port }}"
137-
- "8008" # Patroni REST API port
137+
- "{{ patroni_restapi_port }}"
138138
- "19999" # Netdata
139139
# - "10050" # Zabbix agent
140140
# - ""

0 commit comments

Comments
 (0)