summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Klychkov <aaklychkov@mail.ru>2020-10-23 22:11:14 +0300
committerGitHub <noreply@github.com>2020-10-23 14:11:14 -0500
commite7b2ba4ef65caeed121760086acd1d8236bd74c4 (patch)
treeecce81c7d1e68fe09eb0a5db4c3bd293bc528053
parent2beeeb8a27b22499a70d199a98a50da7e54d1e94 (diff)
downloadansible-e7b2ba4ef65caeed121760086acd1d8236bd74c4.tar.gz
postgresql_pg_hba: fix a crash when a new rule with an 'options' field replaces a rule without or vice versa (#72290)
-rw-r--r--changelogs/fragments/1124-pg_hba-dictkey_bugfix.yaml2
-rw-r--r--lib/ansible/modules/database/postgresql/postgresql_pg_hba.py2
-rw-r--r--test/integration/targets/postgresql/tasks/postgresql_pg_hba.yml14
3 files changed, 17 insertions, 1 deletions
diff --git a/changelogs/fragments/1124-pg_hba-dictkey_bugfix.yaml b/changelogs/fragments/1124-pg_hba-dictkey_bugfix.yaml
new file mode 100644
index 0000000000..5dbda57d7a
--- /dev/null
+++ b/changelogs/fragments/1124-pg_hba-dictkey_bugfix.yaml
@@ -0,0 +1,2 @@
+bugfixes:
+ - postgresql_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/issues/1108).
diff --git a/lib/ansible/modules/database/postgresql/postgresql_pg_hba.py b/lib/ansible/modules/database/postgresql/postgresql_pg_hba.py
index dc223c6e88..47c8993d42 100644
--- a/lib/ansible/modules/database/postgresql/postgresql_pg_hba.py
+++ b/lib/ansible/modules/database/postgresql/postgresql_pg_hba.py
@@ -342,7 +342,7 @@ class PgHba(object):
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
diff --git a/test/integration/targets/postgresql/tasks/postgresql_pg_hba.yml b/test/integration/targets/postgresql/tasks/postgresql_pg_hba.yml
index d4801d48aa..478d893617 100644
--- a/test/integration/targets/postgresql/tasks/postgresql_pg_hba.yml
+++ b/test/integration/targets/postgresql/tasks/postgresql_pg_hba.yml
@@ -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"