fix: pg_hba when multiple users or multiple databases

This commit is contained in:
Adrien Waksberg 2021-10-22 10:26:56 +02:00
parent 44ac805f2c
commit 7b4e1b63f4
4 changed files with 6 additions and 4 deletions

View file

@ -13,6 +13,7 @@ Which is based on [Keep A Changelog](http://keepachangelog.com/)
### Fixed ### Fixed
- fix replication database in pg_hba - fix replication database in pg_hba
- fix pg_hba when multiple users or multiple databases
## v1.0.0 - 2021-09-10 ## v1.0.0 - 2021-09-10

View file

@ -2,7 +2,7 @@
- name: Converge - name: Converge
hosts: all hosts: all
roles: roles:
- ansible-role-postgresql - postgresql
vars: vars:
postgresql_use_official_repository: true postgresql_use_official_repository: true
postgresql_primary: true postgresql_primary: true
@ -12,11 +12,13 @@
- type: hostssl - type: hostssl
databases: databases:
- myappli - myappli
- myappli2
users: all users: all
subnet: samenet subnet: samenet
method: md5 method: md5
postgresql_databases: postgresql_databases:
- name: myappli - name: myappli
- name: myappli2
postgresql_users: postgresql_users:
- name: myuser - name: myuser
database: myappli database: myappli

View file

@ -21,8 +21,7 @@ def test_hba_file(host):
assert path.user == 'root' assert path.user == 'root'
assert path.group == 'root' assert path.group == 'root'
assert path.mode == 0o644 assert path.mode == 0o644
assert path.contains('hostssl "myappli" all samenet md5') assert path.contains('hostssl "myappli","myappli2" all samenet md5')
def test_service(host): def test_service(host):
service = host.service('postgresql@13-main') service = host.service('postgresql@13-main')

View file

@ -2,5 +2,5 @@
local all postgres peer local all postgres peer
{% for conn in postgresql_hba %} {% for conn in postgresql_hba %}
{{ conn.type }} {% if conn.databases in ['all', 'replication'] %}{{ conn.databases }}{% else %}"{{ conn.databases|join('",') }}"{% endif %} {% if conn.users == 'all' %}all{% else %}"{{ conn.users|join('",') }}"{% endif %}{% if conn.type != 'local' %} {{ conn.subnet }}{%endif %} {{ conn.method }} {{ conn.type }} {% if conn.databases in ['all', 'replication'] %}{{ conn.databases }}{% else %}"{{ conn.databases|join('","') }}"{% endif %} {% if conn.users == 'all' %}all{% else %}"{{ conn.users|join('","') }}"{% endif %}{% if conn.type != 'local' %} {{ conn.subnet }}{%endif %} {{ conn.method }}
{% endfor %} {% endfor %}