From d0a9ced47404338d8d59c461e45bfe819ca446bb Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Wed, 21 Oct 2020 22:54:02 +0200 Subject: [PATCH] Update postgresql_pg_hba.py (#1124) (#1151) * Update postgresql_pg_hba.py Fixes #1108 * Create changelog fragment for pull 1124 * Adding a unit test for pg_hba (cherry picked from commit 3a5669991f321ef8afa9f34e0e4cd9dc6024c88d) Co-authored-by: Sebastiaan Mannem --- .../fragments/1124-pg_hba-dictkey bugfix.yaml | 2 ++ .../database/postgresql/postgresql_pg_hba.py | 2 +- .../tasks/postgresql_pg_hba_initial.yml | 14 ++++++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/1124-pg_hba-dictkey bugfix.yaml 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..82fd4e256c --- /dev/null +++ b/changelogs/fragments/1124-pg_hba-dictkey bugfix.yaml @@ -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). diff --git a/plugins/modules/database/postgresql/postgresql_pg_hba.py b/plugins/modules/database/postgresql/postgresql_pg_hba.py index e8f52c1c44..1f484bcfea 100644 --- a/plugins/modules/database/postgresql/postgresql_pg_hba.py +++ b/plugins/modules/database/postgresql/postgresql_pg_hba.py @@ -335,7 +335,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/tests/integration/targets/postgresql_pg_hba/tasks/postgresql_pg_hba_initial.yml b/tests/integration/targets/postgresql_pg_hba/tasks/postgresql_pg_hba_initial.yml index d4801d48aa..478d893617 100644 --- a/tests/integration/targets/postgresql_pg_hba/tasks/postgresql_pg_hba_initial.yml +++ b/tests/integration/targets/postgresql_pg_hba/tasks/postgresql_pg_hba_initial.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"