Skip to content

Commit

Permalink
Update postgresql_pg_hba.py (#1124)
Browse files Browse the repository at this point in the history
* Update postgresql_pg_hba.py

Fixes #1108

* Create changelog fragment for pull 1124

* Adding a unit test for pg_hba
  • Loading branch information
Sebastiaan Mannem authored Oct 21, 2020
1 parent 0f00c65 commit 3a56699
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
2 changes: 2 additions & 0 deletions changelogs/fragments/1124-pg_hba-dictkey bugfix.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- pg_hba - fix a crash when a new rule with an 'options' field replaces a rule without or vice versa (https://github.com/ansible-collections/community.general/pull/1124).
2 changes: 1 addition & 1 deletion plugins/modules/database/postgresql/postgresql_pg_hba.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ def add_rule(self, rule):
ekeys = set(list(oldrule.keys()) + list(rule.keys()))
ekeys.remove('line')
for k in ekeys:
if oldrule[k] != rule[k]:
if oldrule.get(k) != rule.get(k):
raise PgHbaRuleChanged('{0} changes {1}'.format(rule, oldrule))
except PgHbaRuleChanged:
self.rules[key] = rule
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,20 @@
register: pg_hba_change
with_items: "{{pg_hba_test_ips}}"

- name: Able to add options on rule without
postgresql_pg_hba:
dest: "/tmp/pg_hba.conf"
users: "+some"
order: "sud"
state: "present"
contype: "local"
method: "cert"
options: "{{ item }}"
address: ""
with_items:
- ""
- "clientcert=1"

- name: Retain options even if they contain spaces
postgresql_pg_hba:
dest: "/tmp/pg_hba.conf"
Expand Down

0 comments on commit 3a56699

Please sign in to comment.