From fd33dc6cd124d4c3e2fa8d0bed02b8379cf7e8b8 Mon Sep 17 00:00:00 2001 From: Sloane Hertel Date: Fri, 9 Feb 2018 16:32:23 -0500 Subject: [PATCH] [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 --- .../modules/cloud/amazon/ec2_vpc_route_table.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/ansible/modules/cloud/amazon/ec2_vpc_route_table.py b/lib/ansible/modules/cloud/amazon/ec2_vpc_route_table.py index 2607b681f6..0222dd579e 100644 --- a/lib/ansible/modules/cloud/amazon/ec2_vpc_route_table.py +++ b/lib/ansible/modules/cloud/amazon/ec2_vpc_route_table.py @@ -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))