From 86db62c0e95634cf09717340df349725997a3391 Mon Sep 17 00:00:00 2001 From: Ryan Brown Date: Thu, 26 Apr 2018 20:05:41 -0400 Subject: [PATCH] [AWS] report boto3/botocore versions during `fail_json_aws` (#39298) * [AWS] report boto3/botocore versions during `fail_json_aws` When modules call `fail_json_aws` and boto3 is installed, gather the boto3 and botocore versions so that any new AWS module issues will include the user's boto3 installation info. This will make debugging issues where features aren't available yet easier. * PEP8 * Switch to `dict` rather than tuple returns --- lib/ansible/module_utils/aws/core.py | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/lib/ansible/module_utils/aws/core.py b/lib/ansible/module_utils/aws/core.py index 3fb9a6c331..91267cc724 100644 --- a/lib/ansible/module_utils/aws/core.py +++ b/lib/ansible/module_utils/aws/core.py @@ -169,11 +169,29 @@ class AnsibleAWSModule(object): except AttributeError: response = None - if response is None: - self._module.fail_json(msg=message, exception=last_traceback) - else: - self._module.fail_json(msg=message, exception=last_traceback, - **camel_dict_to_snake_dict(response)) + failure = dict( + msg=message, + exception=last_traceback, + **self._gather_versions() + ) + + if response is not None: + failure.update(**camel_dict_to_snake_dict(response)) + + self._module.fail_json(**failure) + + def _gather_versions(self): + """Gather AWS SDK (boto3 and botocore) dependency versions + + Returns {'boto3_version': str, 'botocore_version': str} + Returns {} if neither are installed + """ + if not HAS_BOTO3: + return {} + import boto3 + import botocore + return dict(boto3_version=boto3.__version__, + botocore_version=botocore.__version__) class _RetryingBotoClientWrapper(object):