diff --git a/lib/ansible/module_utils/ec2.py b/lib/ansible/module_utils/ec2.py index 4e654c8f22..f9f18c1227 100644 --- a/lib/ansible/module_utils/ec2.py +++ b/lib/ansible/module_utils/ec2.py @@ -58,8 +58,18 @@ class AnsibleAWSError(Exception): pass +def _botocore_exception_maybe(): + """ + Allow for boto3 not being installed when using these utils by wrapping + botocore.exceptions instead of assigning from it directly. + """ + if HAS_BOTO3: + return botocore.exceptions.ClientError + return type(None) + + class AWSRetry(CloudRetry): - base_class = botocore.exceptions.ClientError + base_class = _botocore_exception_maybe() @staticmethod def status_code_from_exception(error):