From 563a03d94bfc29799ea964dab61a1ba35818b9bb Mon Sep 17 00:00:00 2001 From: Sergio Oliveira Campos Date: Thu, 30 Jul 2020 09:50:24 -0300 Subject: [PATCH] Fixed error msgs on FreeIPABaseModule subclasses When a fail_json is called a SystemExit exeception is raised. Since the FreeIPABaseModule has an internal context manager to deal with exceptions this ContextManager captures the SystemExit. After dealing destroying the kinit session the SystemExit must be raised again to allow the fail_json to work properly. --- plugins/module_utils/ansible_freeipa_module.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/plugins/module_utils/ansible_freeipa_module.py b/plugins/module_utils/ansible_freeipa_module.py index 122ea2e..a59e6e2 100644 --- a/plugins/module_utils/ansible_freeipa_module.py +++ b/plugins/module_utils/ansible_freeipa_module.py @@ -610,12 +610,15 @@ class FreeIPABaseModule(AnsibleModule): exit the module with proper arguments. """ - if exc_val: - self.fail_json(msg=str(exc_val)) - # TODO: shouldn't we also disconnect from api backend? temp_kdestroy(self.ccache_dir, self.ccache_name) + if exc_type == SystemExit: + raise + + if exc_val: + self.fail_json(msg=str(exc_val)) + self.exit_json(changed=self.changed, user=self.exit_args) def get_command_errors(self, command, result): -- 2.26.2