From d871964acab448ce8b54d32a7f1b474d9e90bb9a Mon Sep 17 00:00:00 2001 From: Will Thames Date: Thu, 21 Sep 2017 01:23:48 +1000 Subject: [PATCH] Ensure region is set in ec2_vpc_subnet_facts (#30399) Make requested change in #30370 --- .../modules/cloud/amazon/ec2_vpc_subnet_facts.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/ansible/modules/cloud/amazon/ec2_vpc_subnet_facts.py b/lib/ansible/modules/cloud/amazon/ec2_vpc_subnet_facts.py index f30f0703310..1436d3b4ccc 100644 --- a/lib/ansible/modules/cloud/amazon/ec2_vpc_subnet_facts.py +++ b/lib/ansible/modules/cloud/amazon/ec2_vpc_subnet_facts.py @@ -235,10 +235,13 @@ def main(): region, ec2_url, aws_connect_params = get_aws_connection_info(module, boto3=True) - try: - connection = boto3_conn(module, conn_type='client', resource='ec2', 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)) + if region: + try: + connection = boto3_conn(module, conn_type='client', resource='ec2', 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="Region must be specified") describe_subnets(connection, module)