|
|
@ -203,6 +203,39 @@ def ec2_argument_spec():
|
|
|
|
return spec
|
|
|
|
return spec
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_aws_region(module, boto3=False):
|
|
|
|
|
|
|
|
region = module.params.get('region')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if region:
|
|
|
|
|
|
|
|
return region
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if 'AWS_REGION' in os.environ:
|
|
|
|
|
|
|
|
return os.environ['AWS_REGION']
|
|
|
|
|
|
|
|
if 'AWS_DEFAULT_REGION' in os.environ:
|
|
|
|
|
|
|
|
return os.environ['AWS_DEFAULT_REGION']
|
|
|
|
|
|
|
|
if 'EC2_REGION' in os.environ:
|
|
|
|
|
|
|
|
return os.environ['EC2_REGION']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if not boto3:
|
|
|
|
|
|
|
|
if not HAS_BOTO:
|
|
|
|
|
|
|
|
module.fail_json(msg=missing_required_lib('boto'), exception=BOTO_IMP_ERR)
|
|
|
|
|
|
|
|
# boto.config.get returns None if config not found
|
|
|
|
|
|
|
|
region = boto.config.get('Boto', 'aws_region')
|
|
|
|
|
|
|
|
if region:
|
|
|
|
|
|
|
|
return region
|
|
|
|
|
|
|
|
return boto.config.get('Boto', 'ec2_region')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if not HAS_BOTO3:
|
|
|
|
|
|
|
|
module.fail_json(msg=missing_required_lib('boto3'), exception=BOTO3_IMP_ERR)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# here we don't need to make an additional call, will default to 'us-east-1' if the below evaluates to None.
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
profile_name = module.params.get('profile')
|
|
|
|
|
|
|
|
return botocore.session.Session(profile=profile_name).get_config_variable('region')
|
|
|
|
|
|
|
|
except botocore.exceptions.ProfileNotFound as e:
|
|
|
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_aws_connection_info(module, boto3=False):
|
|
|
|
def get_aws_connection_info(module, boto3=False):
|
|
|
|
|
|
|
|
|
|
|
|
# Check module args for credentials, then check environment vars
|
|
|
|
# Check module args for credentials, then check environment vars
|
|
|
@ -212,7 +245,7 @@ def get_aws_connection_info(module, boto3=False):
|
|
|
|
access_key = module.params.get('aws_access_key')
|
|
|
|
access_key = module.params.get('aws_access_key')
|
|
|
|
secret_key = module.params.get('aws_secret_key')
|
|
|
|
secret_key = module.params.get('aws_secret_key')
|
|
|
|
security_token = module.params.get('security_token')
|
|
|
|
security_token = module.params.get('security_token')
|
|
|
|
region = module.params.get('region')
|
|
|
|
region = get_aws_region(module, boto3)
|
|
|
|
profile_name = module.params.get('profile')
|
|
|
|
profile_name = module.params.get('profile')
|
|
|
|
validate_certs = module.params.get('validate_certs')
|
|
|
|
validate_certs = module.params.get('validate_certs')
|
|
|
|
config = module.params.get('aws_config')
|
|
|
|
config = module.params.get('aws_config')
|
|
|
@ -253,31 +286,6 @@ def get_aws_connection_info(module, boto3=False):
|
|
|
|
# in case secret_key came in as empty string
|
|
|
|
# in case secret_key came in as empty string
|
|
|
|
secret_key = None
|
|
|
|
secret_key = None
|
|
|
|
|
|
|
|
|
|
|
|
if not region:
|
|
|
|
|
|
|
|
if 'AWS_REGION' in os.environ:
|
|
|
|
|
|
|
|
region = os.environ['AWS_REGION']
|
|
|
|
|
|
|
|
elif 'AWS_DEFAULT_REGION' in os.environ:
|
|
|
|
|
|
|
|
region = os.environ['AWS_DEFAULT_REGION']
|
|
|
|
|
|
|
|
elif 'EC2_REGION' in os.environ:
|
|
|
|
|
|
|
|
region = os.environ['EC2_REGION']
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
if not boto3:
|
|
|
|
|
|
|
|
if HAS_BOTO:
|
|
|
|
|
|
|
|
# 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')
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
module.fail_json(msg=missing_required_lib('boto'), exception=BOTO_IMP_ERR)
|
|
|
|
|
|
|
|
elif HAS_BOTO3:
|
|
|
|
|
|
|
|
# here we don't need to make an additional call, will default to 'us-east-1' if the below evaluates to None.
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
region = botocore.session.Session(profile=profile_name).get_config_variable('region')
|
|
|
|
|
|
|
|
except botocore.exceptions.ProfileNotFound as e:
|
|
|
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
module.fail_json(msg=missing_required_lib('boto3'), exception=BOTO3_IMP_ERR)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if not security_token:
|
|
|
|
if not security_token:
|
|
|
|
if os.environ.get('AWS_SECURITY_TOKEN'):
|
|
|
|
if os.environ.get('AWS_SECURITY_TOKEN'):
|
|
|
|
security_token = os.environ['AWS_SECURITY_TOKEN']
|
|
|
|
security_token = os.environ['AWS_SECURITY_TOKEN']
|
|
|
|