Skip to content

Commit f1ea3cf

Browse files
Check syntax of patroni and pg_hba config files (#1297)
Co-authored-by: Vitaliy Kukharik <[email protected]>
1 parent e643f44 commit f1ea3cf

File tree

4 files changed

+31
-2
lines changed

4 files changed

+31
-2
lines changed

automation/roles/patroni/tasks/main.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,19 @@
534534
group: postgres
535535
mode: "0640"
536536

537+
- name: Prepare PostgreSQL | validate generated pg_hba.conf
538+
become: true
539+
become_user: postgres
540+
community.postgresql.postgresql_query:
541+
login_host: "127.0.0.1"
542+
login_port: "{{ postgresql_port }}"
543+
login_user: "{{ patroni_superuser_username }}"
544+
login_password: "{{ patroni_superuser_password }}"
545+
login_db: "postgres"
546+
query: "SELECT * FROM pg_hba_file_rules WHERE error IS NOT NULL"
547+
register: pg_hba_validate_result
548+
failed_when: pg_hba_validate_result.query_result | length > 0
549+
537550
- name: Prepare PostgreSQL | reload for apply the pg_hba.conf
538551
become: true
539552
become_user: postgres
@@ -927,6 +940,20 @@
927940
(('replica' in groups and groups['replica'] | length > 0 and inventory_hostname in groups['replica'] and postgresql_conf_dir != postgresql_data_dir)
928941
or postgresql_exists | default(false) | bool)
929942

943+
- name: Prepare PostgreSQL | validate generated pg_hba.conf
944+
become: true
945+
become_user: postgres
946+
community.postgresql.postgresql_query:
947+
login_host: "127.0.0.1"
948+
login_port: "{{ postgresql_port }}"
949+
login_user: "{{ patroni_superuser_username }}"
950+
login_password: "{{ patroni_superuser_password }}"
951+
login_db: "postgres"
952+
query: "SELECT * FROM pg_hba_file_rules WHERE error IS NOT NULL"
953+
register: pg_hba_validate_result
954+
failed_when: pg_hba_validate_result.query_result | length > 0
955+
when: inventory_hostname == groups['master'][0]
956+
930957
- name: Prepare PostgreSQL | reload for apply the pg_hba.conf
931958
become: true
932959
become_user: postgres

automation/roles/patroni/tasks/patroni.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
ansible.builtin.template:
44
src: templates/patroni.yml.j2
55
dest: "{{ patroni_config_file | default('/etc/patroni/patroni.yml') }}"
6+
validate: patroni --validate-config %s
67
owner: postgres
78
group: postgres
89
mode: "0640"

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ etcd3:
6969
{% if dcs_type == 'consul' %}
7070
consul:
7171
host: 127.0.0.1:8500
72-
checks: []
7372
{% if consul_tls_enable | default(false) | bool %}
7473
scheme: https
7574
cacert: {{ patroni_consul_cacert | default('/etc/patroni/tls/consul/ca.crt') }}

automation/roles/postgresql_schemas/tasks/main.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
name: "{{ item.schema }}"
77
owner: "{{ item.owner }}"
88
login_db: "{{ item.db }}"
9-
login_unix_socket: "{{ postgresql_unix_socket_dir }}"
9+
login_host: "127.0.0.1"
1010
login_port: "{{ postgresql_port }}"
11+
login_user: "{{ patroni_superuser_username }}"
12+
login_password: "{{ patroni_superuser_password }}"
1113
state: present
1214
ignore_errors: true
1315
loop: "{{ postgresql_schemas | flatten(1) }}"

0 commit comments

Comments
 (0)