diff --git a/plugins/module_utils/config_utils.py b/plugins/module_utils/config_utils.py index 99901741..58c7b7c3 100644 --- a/plugins/module_utils/config_utils.py +++ b/plugins/module_utils/config_utils.py @@ -160,7 +160,15 @@ def __exit__(self, exc_type, exc_val, exc_tb): RuntimeError: If there are unsaved changes in the configuration. """ if exc_type: - raise exc_type(f"Exception occurred: {exc_val}") + # module.fail_json will always yield a SystemExit exception + # we need to raise this exception "as is" to avoid ansible warnings + # If however an unexpected exception was risen which was not a result of + # module.fail_json raising this warning is ok, and we need the exceptions + # details to troubleshoot the issue + if isinstance(exc_val, SystemExit): + raise + else: + raise exc_type(f"Exception occurred: {exc_val}") if self.changed and not self._check_mode: raise RuntimeError("Config has changed. Cannot exit without saving.")