1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Fixes #22374: fix route table update in ec2_vpc_route_table module (#27234)

The ec2_vpc_route_table module notifies about a change on the route table when the instance Id of the NAT instance has changed, but in fact, nothing changes. The module call the create_route function the AWS SDK to add a new route with the same cidr. The AWS SDK should return an error instead of nothing.

Call replace_route function instead of create_route when a route table with the same cidr but with different target destination is present.
This commit is contained in:
Antoine Rouaze 2017-09-08 19:27:08 -04:00 committed by ansibot
parent 094856b709
commit f57d51d92c

View file

@ -334,6 +334,11 @@ def route_spec_matches_route(route_spec, route):
return True
def route_spec_matches_route_cidr(route_spec, route):
cidr_attr = 'destination_cidr_block'
return route_spec[cidr_attr] == getattr(route, cidr_attr)
def rename_key(d, old_key, new_key):
d[new_key] = d[old_key]
del d[old_key]
@ -343,16 +348,21 @@ def index_of_matching_route(route_spec, routes_to_match):
for i, route in enumerate(routes_to_match):
if route_spec_matches_route(route_spec, route):
return i
elif route_spec_matches_route_cidr(route_spec, route):
return "replace"
def ensure_routes(vpc_conn, route_table, route_specs, propagating_vgw_ids,
check_mode, purge_routes):
routes_to_match = list(route_table.routes)
route_specs_to_create = []
route_specs_to_recreate = []
for route_spec in route_specs:
i = index_of_matching_route(route_spec, routes_to_match)
if i is None:
route_specs_to_create.append(route_spec)
elif i == "replace":
route_specs_to_recreate.append(route_spec)
else:
del routes_to_match[i]
@ -372,7 +382,7 @@ def ensure_routes(vpc_conn, route_table, route_specs, propagating_vgw_ids,
else:
routes_to_delete.append(r)
changed = bool(routes_to_delete or route_specs_to_create)
changed = bool(routes_to_delete or route_specs_to_create or route_specs_to_recreate)
if changed:
for route in routes_to_delete:
try:
@ -392,6 +402,11 @@ def ensure_routes(vpc_conn, route_table, route_specs, propagating_vgw_ids,
if e.error_code == 'DryRunOperation':
pass
for route_spec in route_specs_to_recreate:
if not check_mode:
vpc_conn.replace_route(route_table.id,
**route_spec)
return {'changed': bool(changed)}