mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-06-28 03:00:23 -07:00
Merge pull request #13166 from defionscode/ec2_util_boto3
Patch to remove dependency on boto when only using boto3
This commit is contained in:
commit
e3a58a883a
1 changed files with 12 additions and 5 deletions
|
@ -29,6 +29,7 @@ import os
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import boto3
|
import boto3
|
||||||
|
import botocore
|
||||||
HAS_BOTO3 = True
|
HAS_BOTO3 = True
|
||||||
except:
|
except:
|
||||||
HAS_BOTO3 = False
|
HAS_BOTO3 = False
|
||||||
|
@ -138,10 +139,16 @@ def get_aws_connection_info(module, boto3=False):
|
||||||
elif 'EC2_REGION' in os.environ:
|
elif 'EC2_REGION' in os.environ:
|
||||||
region = os.environ['EC2_REGION']
|
region = os.environ['EC2_REGION']
|
||||||
else:
|
else:
|
||||||
# boto.config.get returns None if config not found
|
if not boto3:
|
||||||
region = boto.config.get('Boto', 'aws_region')
|
# boto.config.get returns None if config not found
|
||||||
if not region:
|
region = boto.config.get('Boto', 'aws_region')
|
||||||
region = boto.config.get('Boto', 'ec2_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')
|
||||||
|
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 not security_token:
|
||||||
if 'AWS_SECURITY_TOKEN' in os.environ:
|
if 'AWS_SECURITY_TOKEN' in os.environ:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue