Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update cfg mgr exit method #92

Merged
merged 1 commit into from
Apr 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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