From dd0eccf427c47b7e8de747a9dde81462ef957680 Mon Sep 17 00:00:00 2001 From: Robert Estelle Date: Wed, 3 Dec 2014 13:01:44 -0500 Subject: [PATCH] ec2_vpc_route_table - Fix unintended tag search regression. --- .../cloud/amazon/ec2_vpc_route_table.py | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/lib/ansible/modules/extras/cloud/amazon/ec2_vpc_route_table.py b/lib/ansible/modules/extras/cloud/amazon/ec2_vpc_route_table.py index fc736ba451..b6fda27b70 100644 --- a/lib/ansible/modules/extras/cloud/amazon/ec2_vpc_route_table.py +++ b/lib/ansible/modules/extras/cloud/amazon/ec2_vpc_route_table.py @@ -176,6 +176,11 @@ def get_resource_tags(vpc_conn, resource_id): vpc_conn.get_all_tags(filters={'resource-id': resource_id})} +def tags_match(match_tags, candidate_tags): + return all((k in candidate_tags and candidate_tags[k] == v + for k, v in match_tags.iteritems())) + + def ensure_tags(vpc_conn, resource_id, tags, add_only, check_mode): try: cur_tags = get_resource_tags(vpc_conn, resource_id) @@ -204,18 +209,11 @@ def get_route_table_by_id(vpc_conn, vpc_id, route_table_id): def get_route_table_by_tags(vpc_conn, vpc_id, tags): - filters = {'vpc_id': vpc_id} - filters.update(dict((('tag:{0}'.format(t), v) - for t, v in tags.iteritems()))) - route_tables = vpc_conn.get_all_route_tables(filters=filters) - - if not route_tables: - return None - elif len(route_tables) == 1: - return route_tables[0] - - raise RouteTableException( - 'Found more than one route table based on the supplied tags, aborting') + route_tables = vpc_conn.get_all_route_tables(filters={'vpc_id': vpc_id}) + for route_table in route_tables: + this_tags = get_resource_tags(vpc_conn, route_table.id) + if tags_match(tags, this_tags): + return route_table def route_spec_matches_route(route_spec, route):