mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-02 14:40:19 -07:00
Move profile and region checking to module_utils.ec2 (#31921)
* Move profile and region checking to module_utils.ec2 Remove ProfileNotFound checking from individual modules There are plenty of `if not region:` checks that could be removed, once more thorough testing of this change has occured The ec2_asg, iam_managed_policy and ec2_vpc_subnet_facts modules would also benefit from this change but as they do not have tests and are marked stableinterface, they do not get this change.
This commit is contained in:
parent
cd80f26035
commit
c93ddf5473
11 changed files with 37 additions and 65 deletions
|
@ -90,16 +90,8 @@ def main():
|
|||
|
||||
# Set up connection
|
||||
region, ec2_url, aws_connect_params = get_aws_connection_info(module, boto3=HAS_BOTO3)
|
||||
|
||||
# Set up connection
|
||||
if region:
|
||||
try:
|
||||
connection = boto3_conn(module, conn_type='client', resource='s3', region=region, endpoint=ec2_url,
|
||||
**aws_connect_params)
|
||||
except (botocore.exceptions.NoCredentialsError, botocore.exceptions.ProfileNotFound) as e:
|
||||
module.fail_json(msg=e.message, exception=traceback.format_exc(), **camel_dict_to_snake_dict(e.response))
|
||||
else:
|
||||
module.fail_json(msg="AWS region must be specified (like: us-east-1)")
|
||||
connection = boto3_conn(module, conn_type='client', resource='s3', region=region, endpoint=ec2_url,
|
||||
**aws_connect_params)
|
||||
|
||||
# Gather results
|
||||
result['buckets'] = get_bucket_list(module, connection)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue