From 121990d8c5084ac759ad8a1c1d46b3eab7a72ff7 Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Mon, 25 Mar 2019 18:00:20 +0100 Subject: [PATCH] openssl_dhparam: fix state=absent (#54296) * Fix remove. * Add changelog. --- .../fragments/54296-openssl_dhparam-remove.yaml | 2 ++ lib/ansible/modules/crypto/openssl_dhparam.py | 16 ++++++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) create mode 100644 changelogs/fragments/54296-openssl_dhparam-remove.yaml diff --git a/changelogs/fragments/54296-openssl_dhparam-remove.yaml b/changelogs/fragments/54296-openssl_dhparam-remove.yaml new file mode 100644 index 0000000000..ad3c05bbe0 --- /dev/null +++ b/changelogs/fragments/54296-openssl_dhparam-remove.yaml @@ -0,0 +1,2 @@ +bugfixes: +- "openssl_dhparam - fix ``state=absent`` idempotency and ``changed`` flag." diff --git a/lib/ansible/modules/crypto/openssl_dhparam.py b/lib/ansible/modules/crypto/openssl_dhparam.py index a7e3d93536..16c8a297e5 100644 --- a/lib/ansible/modules/crypto/openssl_dhparam.py +++ b/lib/ansible/modules/crypto/openssl_dhparam.py @@ -136,6 +136,13 @@ class DHParameter(object): self.changed = changed + def remove(self, module): + try: + os.remove(self.path) + self.changed = True + except OSError as exc: + module.fail_json(msg=to_native(exc)) + def check(self, module): """Ensure the resource is in its desired state.""" if self.force: @@ -223,10 +230,11 @@ def main(): result['changed'] = os.path.exists(module.params['path']) module.exit_json(**result) - try: - os.remove(module.params['path']) - except OSError as exc: - module.fail_json(msg=to_native(exc)) + if os.path.exists(module.params['path']): + try: + dhparam.remove(module) + except Exception as exc: + module.fail_json(msg=to_native(exc)) result = dhparam.dump()