From 5ceb07c65af0539d05af27bfd03f7b6a33265aea Mon Sep 17 00:00:00 2001 From: Will Thames Date: Sat, 25 Oct 2014 18:17:57 +1000 Subject: [PATCH 1/2] Add Frankfurt AWS region --- lib/ansible/module_utils/ec2.py | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/ansible/module_utils/ec2.py b/lib/ansible/module_utils/ec2.py index b4558ef0a4..3d3040068f 100644 --- a/lib/ansible/module_utils/ec2.py +++ b/lib/ansible/module_utils/ec2.py @@ -37,6 +37,7 @@ AWS_REGIONS = [ 'ap-southeast-1', 'ap-southeast-2', 'eu-west-1', + 'eu-central-1', 'sa-east-1', 'us-east-1', 'us-west-1', From 2397926b948ec827bef4debb108b7806a7a039f1 Mon Sep 17 00:00:00 2001 From: Will Thames Date: Sat, 1 Nov 2014 12:36:31 +1000 Subject: [PATCH 2/2] Handle case where boto needs an upgrade to recognise a new region Raise an exception if boto does not yet know about a region. --- lib/ansible/module_utils/ec2.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/ansible/module_utils/ec2.py b/lib/ansible/module_utils/ec2.py index 3d3040068f..5db6555365 100644 --- a/lib/ansible/module_utils/ec2.py +++ b/lib/ansible/module_utils/ec2.py @@ -164,6 +164,11 @@ def boto_fix_security_token_in_profile(conn, profile_name): def connect_to_aws(aws_module, region, **params): conn = aws_module.connect_to_region(region, **params) + if not conn: + if region not in [aws_module_region.name for aws_module_region in aws_module.regions()]: + raise StandardError("Region %s does not seem to be available for aws module %s. If the region definitely exists, you may need to upgrade boto" % (region, aws_module.__name__)) + else: + raise StandardError("Unknown problem connecting to region %s for aws module %s." % (region, aws_module.__name__)) if params.get('profile_name'): conn = boto_fix_security_token_in_profile(conn, params['profile_name']) return conn @@ -179,13 +184,13 @@ def ec2_connect(module): if region: try: ec2 = connect_to_aws(boto.ec2, region, **boto_params) - except boto.exception.NoAuthHandlerFound, e: + except (boto.exception.NoAuthHandlerFound, StandardError), e: module.fail_json(msg=str(e)) # Otherwise, no region so we fallback to the old connection method elif ec2_url: try: ec2 = boto.connect_ec2_endpoint(ec2_url, **boto_params) - except boto.exception.NoAuthHandlerFound, e: + except (boto.exception.NoAuthHandlerFound, StandardError), e: module.fail_json(msg=str(e)) else: module.fail_json(msg="Either region or ec2_url must be specified")