Skip to content

Commit

Permalink
Add fail method that knows how to handle AnsibleAWSErrors (#1997)
Browse files Browse the repository at this point in the history
Add fail method that knows how to handle AnsibleAWSErrors

SUMMARY
Adds fail_json_aws_error() to AnsibeAWSModule this is just a simple wrapper around fail_json() and fail_json_aws() that knows how to route AnsibleAWSError exceptions (with and without triggering exceptions)
ISSUE TYPE

Feature Pull Request

COMPONENT NAME
module_utils/modules
ADDITIONAL INFORMATION

Reviewed-by: Alina Buzachis
  • Loading branch information
tremble authored Feb 27, 2024
1 parent d8b0996 commit b251003
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/20240227-fail_aws_error.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- AnsibeAWSModule - added ``fail_json_aws_error()`` as a wrapper for ``fail_json()`` and ``fail_json_aws()`` when passed an ``AnsibleAWSError`` exception (https://github.com/ansible-collections/amazon.aws/pull/1997).
6 changes: 6 additions & 0 deletions plugins/module_utils/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,12 @@ def fail_json_aws(self, exception, msg=None, **kwargs):

self.fail_json(**failure)

def fail_json_aws_error(self, exception):
"""A helper to call the right failure mode after catching an AnsibleAWSError"""
if exception.exception:
self.fail_json_aws(exception.exception, msg=exception.message)
self.fail_json(msg=exception.message)

def _gather_versions(self):
"""Gather AWS SDK (boto3 and botocore) dependency versions
Expand Down

0 comments on commit b251003

Please sign in to comment.