mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
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:
parent
094856b709
commit
f57d51d92c
1 changed files with 16 additions and 1 deletions
|
@ -334,6 +334,11 @@ def route_spec_matches_route(route_spec, route):
|
||||||
return True
|
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):
|
def rename_key(d, old_key, new_key):
|
||||||
d[new_key] = d[old_key]
|
d[new_key] = d[old_key]
|
||||||
del 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):
|
for i, route in enumerate(routes_to_match):
|
||||||
if route_spec_matches_route(route_spec, route):
|
if route_spec_matches_route(route_spec, route):
|
||||||
return i
|
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,
|
def ensure_routes(vpc_conn, route_table, route_specs, propagating_vgw_ids,
|
||||||
check_mode, purge_routes):
|
check_mode, purge_routes):
|
||||||
routes_to_match = list(route_table.routes)
|
routes_to_match = list(route_table.routes)
|
||||||
route_specs_to_create = []
|
route_specs_to_create = []
|
||||||
|
route_specs_to_recreate = []
|
||||||
for route_spec in route_specs:
|
for route_spec in route_specs:
|
||||||
i = index_of_matching_route(route_spec, routes_to_match)
|
i = index_of_matching_route(route_spec, routes_to_match)
|
||||||
if i is None:
|
if i is None:
|
||||||
route_specs_to_create.append(route_spec)
|
route_specs_to_create.append(route_spec)
|
||||||
|
elif i == "replace":
|
||||||
|
route_specs_to_recreate.append(route_spec)
|
||||||
else:
|
else:
|
||||||
del routes_to_match[i]
|
del routes_to_match[i]
|
||||||
|
|
||||||
|
@ -372,7 +382,7 @@ def ensure_routes(vpc_conn, route_table, route_specs, propagating_vgw_ids,
|
||||||
else:
|
else:
|
||||||
routes_to_delete.append(r)
|
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:
|
if changed:
|
||||||
for route in routes_to_delete:
|
for route in routes_to_delete:
|
||||||
try:
|
try:
|
||||||
|
@ -392,6 +402,11 @@ def ensure_routes(vpc_conn, route_table, route_specs, propagating_vgw_ids,
|
||||||
if e.error_code == 'DryRunOperation':
|
if e.error_code == 'DryRunOperation':
|
||||||
pass
|
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)}
|
return {'changed': bool(changed)}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue