From 1b76a9cef2d74eba9fd786e43f1cf3364a8ac501 Mon Sep 17 00:00:00 2001 From: Jonathan Davila Date: Fri, 13 Nov 2015 18:19:09 -0700 Subject: [PATCH 1/2] Patch to remove dependency on boto when only using boto3 Updated with explicit check for HAS_BOTO3 --- lib/ansible/module_utils/ec2.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/ansible/module_utils/ec2.py b/lib/ansible/module_utils/ec2.py index ac799772c2c..2edfd9e5d83 100644 --- a/lib/ansible/module_utils/ec2.py +++ b/lib/ansible/module_utils/ec2.py @@ -29,6 +29,7 @@ import os try: import boto3 + import botocore HAS_BOTO3 = True except: HAS_BOTO3 = False @@ -129,10 +130,14 @@ def get_aws_connection_info(module, boto3=False): elif 'EC2_REGION' in os.environ: region = os.environ['EC2_REGION'] else: - # boto.config.get returns None if config not found - region = boto.config.get('Boto', 'aws_region') - if not region: - region = boto.config.get('Boto', 'ec2_region') + if not boto3: + # boto.config.get returns None if config not found + region = boto.config.get('Boto', 'aws_region') + if not region: + region = boto.config.get('Boto', 'ec2_region') + elif boto3 and HAS_BOTO3: + # here we don't need to make an additional call, will default to 'us-east-1' if the below evaluates to None. + region = botocore.session.get_session().get_config_variable('region') if not security_token: if 'AWS_SECURITY_TOKEN' in os.environ: From 041e1979c40725b55bbf9735e26fcaaea5cdec9f Mon Sep 17 00:00:00 2001 From: Jonathan Davila Date: Mon, 25 Jan 2016 17:40:20 -0500 Subject: [PATCH 2/2] Boto3 error handle fix --- lib/ansible/module_utils/ec2.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/ansible/module_utils/ec2.py b/lib/ansible/module_utils/ec2.py index fdb326a7f1c..7a30955db8b 100644 --- a/lib/ansible/module_utils/ec2.py +++ b/lib/ansible/module_utils/ec2.py @@ -147,7 +147,9 @@ def get_aws_connection_info(module, boto3=False): elif boto3 and HAS_BOTO3: # here we don't need to make an additional call, will default to 'us-east-1' if the below evaluates to None. region = botocore.session.get_session().get_config_variable('region') - + elif boto3 and not HAS_BOTO3: + module.fail_json("Boto3 is required for this module. Please install boto3 and try again") + if not security_token: if 'AWS_SECURITY_TOKEN' in os.environ: security_token = os.environ['AWS_SECURITY_TOKEN']