[cloud] Make ec2_vpc_route_table wait for the route to propagate (#35975)

* Stabilize ec2_vpc_route_table

Wait for route table to be present before attempting to use it

Sleep before getting the final state of the route table in case modifications are incomplete

* Conditionally wait if changes were made

* Simplify logic
pull/30428/head
Sloane Hertel 7 years ago committed by Ryan Brown
parent 01ba3a4efc
commit fd33dc6cd1

@ -224,6 +224,7 @@ route_table:
'''
import re
from time import sleep
from ansible.module_utils.aws.core import AnsibleAWSModule
from ansible.module_utils.ec2 import ec2_argument_spec, boto3_conn, get_aws_connection_info
from ansible.module_utils.ec2 import ansible_dict_to_boto3_filter_list
@ -647,6 +648,12 @@ def ensure_route_table_present(connection, module):
if not module.check_mode:
try:
route_table = connection.create_route_table(VpcId=vpc_id)['RouteTable']
# try to wait for route table to be present before moving on
for attempt in range(5):
if not get_route_table_by_id(connection, module, route_table['RouteTableId']):
sleep(2)
else:
break
except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:
module.fail_json_aws(e, msg="Error creating route table")
else:
@ -678,6 +685,9 @@ def ensure_route_table_present(connection, module):
purge_subnets=purge_subnets)
changed = changed or result['changed']
if changed:
# pause to allow route table routes/subnets/associations to be updated before exiting with final state
sleep(5)
module.exit_json(changed=changed, route_table=get_route_table_info(connection, module, route_table))

Loading…
Cancel
Save