mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-10-07 00:44:01 -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
|
@ -113,7 +113,7 @@ from ansible.module_utils._text import to_native
|
|||
|
||||
try:
|
||||
import boto3
|
||||
from botocore.exceptions import ClientError, NoCredentialsError, ProfileNotFound, NoRegionError, WaiterError
|
||||
from botocore.exceptions import ClientError, WaiterError
|
||||
HAS_BOTO3 = True
|
||||
except ImportError:
|
||||
HAS_BOTO3 = False
|
||||
|
@ -174,12 +174,8 @@ def main():
|
|||
module.fail_json(msg='botocore and boto3 are required.')
|
||||
|
||||
region, ec2_url, aws_connect_kwargs = get_aws_connection_info(module, boto3=True)
|
||||
if not region:
|
||||
module.fail_json(msg="Region must be provided.")
|
||||
try:
|
||||
client = boto3_conn(module, conn_type='client', resource='ec2', region=region, endpoint=ec2_url, **aws_connect_kwargs)
|
||||
except (NoCredentialsError, ProfileNotFound) as e:
|
||||
module.fail_json(msg="Can't authorize connection - %s" % to_native(e))
|
||||
client = boto3_conn(module, conn_type='client', resource='ec2',
|
||||
region=region, endpoint=ec2_url, **aws_connect_kwargs)
|
||||
|
||||
copy_snapshot(module, client)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue