Fixing check mode support for vpc route tables
Loop compatibility for dry run exception handling Route table deletion dry run handler Fixing regression in propagating_vgw_ids default value Adjusting truthiness of changed attribute for route manipulation Updating propagating_vgw_ids default in docstring
This commit is contained in:
parent
d02e26c38f
commit
ddcc15a60f
1 changed files with 27 additions and 16 deletions
|
@ -31,6 +31,7 @@ options:
|
||||||
propagating_vgw_ids:
|
propagating_vgw_ids:
|
||||||
description:
|
description:
|
||||||
- "Enable route propagation from virtual gateways specified by ID."
|
- "Enable route propagation from virtual gateways specified by ID."
|
||||||
|
default: None
|
||||||
required: false
|
required: false
|
||||||
route_table_id:
|
route_table_id:
|
||||||
description:
|
description:
|
||||||
|
@ -323,15 +324,24 @@ def ensure_routes(vpc_conn, route_table, route_specs, propagating_vgw_ids,
|
||||||
changed = routes_to_delete or route_specs_to_create
|
changed = routes_to_delete or route_specs_to_create
|
||||||
if changed:
|
if changed:
|
||||||
for route_spec in route_specs_to_create:
|
for route_spec in route_specs_to_create:
|
||||||
|
try:
|
||||||
vpc_conn.create_route(route_table.id,
|
vpc_conn.create_route(route_table.id,
|
||||||
dry_run=check_mode,
|
dry_run=check_mode,
|
||||||
**route_spec)
|
**route_spec)
|
||||||
|
except EC2ResponseError as e:
|
||||||
|
if e.error_code == 'DryRunOperation':
|
||||||
|
pass
|
||||||
|
|
||||||
for route in routes_to_delete:
|
for route in routes_to_delete:
|
||||||
|
try:
|
||||||
vpc_conn.delete_route(route_table.id,
|
vpc_conn.delete_route(route_table.id,
|
||||||
route.destination_cidr_block,
|
route.destination_cidr_block,
|
||||||
dry_run=check_mode)
|
dry_run=check_mode)
|
||||||
return {'changed': changed}
|
except EC2ResponseError as e:
|
||||||
|
if e.error_code == 'DryRunOperation':
|
||||||
|
pass
|
||||||
|
|
||||||
|
return {'changed': bool(changed)}
|
||||||
|
|
||||||
|
|
||||||
def ensure_subnet_association(vpc_conn, vpc_id, route_table_id, subnet_id,
|
def ensure_subnet_association(vpc_conn, vpc_id, route_table_id, subnet_id,
|
||||||
|
@ -406,7 +416,6 @@ def ensure_route_table_absent(connection, module):
|
||||||
route_table_id = module.params.get('route_table_id')
|
route_table_id = module.params.get('route_table_id')
|
||||||
tags = module.params.get('tags')
|
tags = module.params.get('tags')
|
||||||
vpc_id = module.params.get('vpc_id')
|
vpc_id = module.params.get('vpc_id')
|
||||||
check_mode = module.params.get('check_mode')
|
|
||||||
|
|
||||||
if lookup == 'tag':
|
if lookup == 'tag':
|
||||||
if tags is not None:
|
if tags is not None:
|
||||||
|
@ -428,8 +437,11 @@ def ensure_route_table_absent(connection, module):
|
||||||
return {'changed': False}
|
return {'changed': False}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
connection.delete_route_table(route_table.id, dry_run=check_mode)
|
connection.delete_route_table(route_table.id, dry_run=module.check_mode)
|
||||||
except EC2ResponseError as e:
|
except EC2ResponseError as e:
|
||||||
|
if e.error_code == 'DryRunOperation':
|
||||||
|
pass
|
||||||
|
else:
|
||||||
module.fail_json(msg=e.message)
|
module.fail_json(msg=e.message)
|
||||||
|
|
||||||
return {'changed': True}
|
return {'changed': True}
|
||||||
|
@ -465,12 +477,11 @@ def create_route_spec(connection, routes, vpc_id):
|
||||||
def ensure_route_table_present(connection, module):
|
def ensure_route_table_present(connection, module):
|
||||||
|
|
||||||
lookup = module.params.get('lookup')
|
lookup = module.params.get('lookup')
|
||||||
propagating_vgw_ids = module.params.get('propagating_vgw_ids', [])
|
propagating_vgw_ids = module.params.get('propagating_vgw_ids')
|
||||||
route_table_id = module.params.get('route_table_id')
|
route_table_id = module.params.get('route_table_id')
|
||||||
subnets = module.params.get('subnets')
|
subnets = module.params.get('subnets')
|
||||||
tags = module.params.get('tags')
|
tags = module.params.get('tags')
|
||||||
vpc_id = module.params.get('vpc_id')
|
vpc_id = module.params.get('vpc_id')
|
||||||
check_mode = module.params.get('check_mode')
|
|
||||||
try:
|
try:
|
||||||
routes = create_route_spec(connection, module.params.get('routes'), vpc_id)
|
routes = create_route_spec(connection, module.params.get('routes'), vpc_id)
|
||||||
except AnsibleIgwSearchException as e:
|
except AnsibleIgwSearchException as e:
|
||||||
|
@ -508,7 +519,7 @@ def ensure_route_table_present(connection, module):
|
||||||
|
|
||||||
if routes is not None:
|
if routes is not None:
|
||||||
try:
|
try:
|
||||||
result = ensure_routes(connection, route_table, routes, propagating_vgw_ids, check_mode)
|
result = ensure_routes(connection, route_table, routes, propagating_vgw_ids, module.check_mode)
|
||||||
changed = changed or result['changed']
|
changed = changed or result['changed']
|
||||||
except EC2ResponseError as e:
|
except EC2ResponseError as e:
|
||||||
module.fail_json(msg=e.message)
|
module.fail_json(msg=e.message)
|
||||||
|
@ -516,12 +527,12 @@ def ensure_route_table_present(connection, module):
|
||||||
if propagating_vgw_ids is not None:
|
if propagating_vgw_ids is not None:
|
||||||
result = ensure_propagation(connection, route_table,
|
result = ensure_propagation(connection, route_table,
|
||||||
propagating_vgw_ids,
|
propagating_vgw_ids,
|
||||||
check_mode=check_mode)
|
check_mode=module.check_mode)
|
||||||
changed = changed or result['changed']
|
changed = changed or result['changed']
|
||||||
|
|
||||||
if not tags_valid and tags is not None:
|
if not tags_valid and tags is not None:
|
||||||
result = ensure_tags(connection, route_table.id, tags,
|
result = ensure_tags(connection, route_table.id, tags,
|
||||||
add_only=True, check_mode=check_mode)
|
add_only=True, check_mode=module.check_mode)
|
||||||
changed = changed or result['changed']
|
changed = changed or result['changed']
|
||||||
|
|
||||||
if subnets:
|
if subnets:
|
||||||
|
@ -535,7 +546,7 @@ def ensure_route_table_present(connection, module):
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
result = ensure_subnet_associations(connection, vpc_id, route_table, associated_subnets, check_mode)
|
result = ensure_subnet_associations(connection, vpc_id, route_table, associated_subnets, module.check_mode)
|
||||||
changed = changed or result['changed']
|
changed = changed or result['changed']
|
||||||
except EC2ResponseError as e:
|
except EC2ResponseError as e:
|
||||||
raise AnsibleRouteTableException(
|
raise AnsibleRouteTableException(
|
||||||
|
|
Loading…
Reference in a new issue