Skip to content

Commit 1351b5f

Browse files
authored
fix: Set Patroni TLS vars only when HTTPS is enabled (#1286)
1 parent 5b8aad0 commit 1351b5f

File tree

8 files changed

+33
-15
lines changed

8 files changed

+33
-15
lines changed

automation/molecule/tests/patroni/patroni.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
| default('8008') }}/leader
88
method: GET
99
return_content: true
10-
ca_path: "{{ patroni_restapi_cafile | default('/etc/tls/ca.crt') }}"
10+
ca_path: "{{ patroni_restapi_cafile | default(omit, true) }}"
1111
register: patroni_response
1212
failed_when: "'running' not in patroni_response.json.state"
1313

automation/playbooks/add_node.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@
329329
when: pg_probackup_install | default(false) | bool
330330

331331
- role: vitabaks.autobase.pgbouncer
332-
when: pgbouncer_install | default(false) | bool
332+
when: pgbouncer_install | default(true) | bool
333333

334334
- role: vitabaks.autobase.pgpass
335335

automation/playbooks/config_pgcluster.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@
4040
name: vitabaks.autobase.bind_address
4141
tags: always
4242

43+
- name: Set default variables
44+
ansible.builtin.import_role:
45+
name: vitabaks.autobase.common
46+
tags: always
47+
4348
- name: "[Prepare] Set maintenance variable"
4449
ansible.builtin.set_fact:
4550
postgresql_cluster_maintenance: true
@@ -52,7 +57,7 @@
5257
| default(patroni_bind_address | default(bind_address, true), true) }}:{{ patroni_restapi_port
5358
| default('8008') }}/leader
5459
status_code: 200
55-
ca_path: "{{ patroni_restapi_cafile | default('/etc/tls/ca.crt') }}"
60+
ca_path: "{{ patroni_restapi_cafile | default(omit, true) }}"
5661
register: patroni_leader_result
5762
changed_when: false
5863
failed_when: false

automation/playbooks/deploy_pgcluster.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@
314314
- role: vitabaks.autobase.cron
315315

316316
- role: vitabaks.autobase.pgbouncer
317-
when: pgbouncer_install | default(false) | bool
317+
when: pgbouncer_install | default(true) | bool
318318

319319
- role: vitabaks.autobase.pgpass
320320

automation/playbooks/pg_upgrade.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,18 @@
1515
ansible.builtin.include_role:
1616
name: vitabaks.autobase.bind_address
1717

18+
- name: Set default variables
19+
ansible.builtin.import_role:
20+
name: vitabaks.autobase.common
21+
1822
- name: "[Prepare] Get Patroni Cluster Leader Node"
1923
ansible.builtin.uri:
2024
url: >-
2125
{{ patroni_restapi_protocol | default('https') }}://{{ patroni_restapi_connect_addr
2226
| default(patroni_bind_address | default(bind_address, true), true) }}:{{ patroni_restapi_port
2327
| default('8008') }}/leader
2428
status_code: 200
25-
ca_path: "{{ patroni_restapi_cafile | default('/etc/tls/ca.crt') }}"
29+
ca_path: "{{ patroni_restapi_cafile | default(omit, true) }}"
2630
register: patroni_leader_result
2731
changed_when: false
2832
failed_when: false

automation/playbooks/update_pgcluster.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@
66
become_method: sudo
77
any_errors_fatal: true
88
tasks:
9-
- name: Set default variables
10-
ansible.builtin.import_role:
11-
name: vitabaks.autobase.common
12-
139
- name: Gather package facts
1410
ansible.builtin.package_facts:
1511
manager: auto
@@ -21,14 +17,19 @@
2117
name: vitabaks.autobase.bind_address
2218
tags: always
2319

20+
- name: Set default variables
21+
ansible.builtin.import_role:
22+
name: vitabaks.autobase.common
23+
tags: always
24+
2425
- name: "[Prepare] Get Patroni Cluster Leader Node"
2526
ansible.builtin.uri:
2627
url: >-
2728
{{ patroni_restapi_protocol | default('https') }}://{{ patroni_restapi_connect_addr
2829
| default(patroni_bind_address | default(bind_address, true), true) }}:{{ patroni_restapi_port
2930
| default('8008') }}/leader
3031
status_code: 200
31-
ca_path: "{{ patroni_restapi_cafile | default('/etc/tls/ca.crt') }}"
32+
ca_path: "{{ patroni_restapi_cafile | default(omit, true) }}"
3233
register: patroni_leader_result
3334
changed_when: false
3435
failed_when: false

automation/roles/common/defaults/main.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ patroni_superuser_username: "postgres"
1616
patroni_superuser_password: "" # Please specify a password. If not defined, will be generated automatically during deployment.
1717
patroni_superuser_auth_options:
1818
- { option: "sslmode", value: "{{ 'require' if tls_cert_generate | bool else 'disable' }}" } # or 'verify-ca', 'verify-full'
19-
- { option: "sslrootcert", value: "{{ tls_dir }}/{{ tls_ca_cert }}" } # or 'system'
19+
- { option: "sslrootcert", value: "{{ tls_dir ~ '/' ~ tls_ca_cert if tls_cert_generate | bool else '' }}" } # or 'system'
2020
patroni_replication_username: "replicator"
2121
patroni_replication_password: "" # Please specify a password. If not defined, will be generated automatically during deployment.
2222
patroni_replication_auth_options:
2323
- { option: "sslmode", value: "{{ 'require' if tls_cert_generate | bool else 'disable' }}" } # or 'verify-ca', 'verify-full'
24-
- { option: "sslrootcert", value: "{{ tls_dir }}/{{ tls_ca_cert }}" } # or 'system'
24+
- { option: "sslrootcert", value: "{{ tls_dir ~ '/' ~ tls_ca_cert if tls_cert_generate | bool else '' }}" } # or 'system'
2525
# Note: if sslmode: verify-full, and your certificate doesn't have IP address in the SAN,
2626
# set also the option postgresql_connect_addr to ensure TLS certificate validation is successful.
2727

@@ -508,9 +508,9 @@ pgbouncer_pools:
508508
############################################################
509509

510510
patroni_restapi_protocol: "{{ 'https' if tls_cert_generate | bool else 'http' }}"
511-
patroni_restapi_certfile: "{{ tls_dir }}/{{ tls_cert }}"
512-
patroni_restapi_keyfile: "{{ tls_dir }}/{{ tls_privatekey }}"
513-
patroni_restapi_cafile: "{{ tls_dir }}/{{ tls_ca_cert }}"
511+
patroni_restapi_certfile: "{{ tls_dir ~ '/' ~ tls_cert if patroni_restapi_protocol == 'https' else omit }}"
512+
patroni_restapi_keyfile: "{{ tls_dir ~ '/' ~ tls_privatekey if patroni_restapi_protocol == 'https' else omit }}"
513+
patroni_restapi_cafile: "{{ tls_dir ~ '/' ~ tls_ca_cert if patroni_restapi_protocol == 'https' else omit }}"
514514
# patroni_restapi_connect_addr: "{{ ansible_hostname }}" # or 'ansible_fqdn'. Set if you need connection to be established by domain name, not IP.
515515
patroni_restapi_listen_addr: "0.0.0.0" # Listen on all interfaces. Or use "{{ bind_address }}" to listen on a specific IP address.
516516
patroni_restapi_port: 8008

automation/roles/patroni/templates/patroni.yml.j2

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,13 +169,21 @@ postgresql:
169169
username: {{ patroni_replication_username }}
170170
password: {{ patroni_replication_password }}
171171
{% for parameter in patroni_replication_auth_options %}
172+
{% if parameter.option == 'sslrootcert' and parameter.value | length > 0 %}
172173
{{ parameter.option }}: {{ parameter.value }}
174+
{% elif parameter.option != 'sslrootcert' %}
175+
{{ parameter.option }}: {{ parameter.value }}
176+
{% endif %}
173177
{% endfor %}
174178
superuser:
175179
username: {{ patroni_superuser_username }}
176180
password: {{ patroni_superuser_password }}
177181
{% for parameter in patroni_superuser_auth_options %}
182+
{% if parameter.option == 'sslrootcert' and parameter.value | length > 0 %}
183+
{{ parameter.option }}: {{ parameter.value }}
184+
{% elif parameter.option != 'sslrootcert' %}
178185
{{ parameter.option }}: {{ parameter.value }}
186+
{% endif %}
179187
{% endfor %}
180188
# rewind: # Has no effect on postgres 10 and lower
181189
# username: rewind_user

0 commit comments

Comments
 (0)