Skip to content

Commit

Permalink
update cfg mgr exit method
Browse files Browse the repository at this point in the history
  • Loading branch information
rekup committed Apr 13, 2024
1 parent a6237e6 commit 7eee695
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion plugins/module_utils/config_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.")

Expand Down

0 comments on commit 7eee695

Please sign in to comment.