Skip to content

Commit

Permalink
update cfg mgr exit method (puzzle#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
rekup authored and KiLLuuuhh committed Apr 16, 2024
1 parent 6ffc260 commit 21dab27
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions plugins/module_utils/config_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,13 @@ def __exit__(self, exc_type, exc_val, exc_tb):
RuntimeError: If there are unsaved changes in the configuration.
"""
if exc_type:
# 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
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 21dab27

Please sign in to comment.