From 938d60472af6f6b20d0d7a0c616e36b499e79c12 Mon Sep 17 00:00:00 2001 From: Sloane Hertel Date: Thu, 15 Jun 2017 15:52:56 -0400 Subject: [PATCH] [cloud] ec2.py: add region to the aws_connect_kwargs before creating vpc connection Fixes #25673 (#25749) * add region to the aws_connect_kwargs before creating vpc connection * remove unused import --- lib/ansible/modules/cloud/amazon/ec2.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/ansible/modules/cloud/amazon/ec2.py b/lib/ansible/modules/cloud/amazon/ec2.py index a1530a8c8c..c983c3eb87 100644 --- a/lib/ansible/modules/cloud/amazon/ec2.py +++ b/lib/ansible/modules/cloud/amazon/ec2.py @@ -1642,12 +1642,15 @@ def main(): module.fail_json(msg='boto required for this module') try: - _, ec2_url, aws_connect_kwargs = get_aws_connection_info(module) + region, ec2_url, aws_connect_kwargs = get_aws_connection_info(module) if module.params.get('region') or not module.params.get('ec2_url'): ec2 = ec2_connect(module) elif module.params.get('ec2_url'): ec2 = connect_ec2_endpoint(ec2_url, **aws_connect_kwargs) + if 'region' not in aws_connect_kwargs: + aws_connect_kwargs['region'] = ec2.region + vpc = connect_vpc(**aws_connect_kwargs) except boto.exception.NoAuthHandlerFound as e: module.fail_json(msg="Failed to get connection: %s" % e.message, exception=traceback.format_exc())