From ca88231df6225f81a634c72db810ffa6e588c09b Mon Sep 17 00:00:00 2001 From: Stefan Horning Date: Wed, 24 Mar 2021 14:41:54 +0100 Subject: [PATCH] ec2_vpc_route_table: Don't fail if a route was already created. (#359) This commit was initially merged in https://github.com/ansible-collections/community.aws See: https://github.com/ansible-collections/community.aws/commit/73d60e5c05455b773c2a9976b201346793a05fb2 --- plugins/modules/ec2_vpc_route_table.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/plugins/modules/ec2_vpc_route_table.py b/plugins/modules/ec2_vpc_route_table.py index fc7c02c6706..6549f78881b 100644 --- a/plugins/modules/ec2_vpc_route_table.py +++ b/plugins/modules/ec2_vpc_route_table.py @@ -492,20 +492,16 @@ def ensure_routes(connection=None, module=None, route_table=None, route_specs=No for route_spec in route_specs_to_recreate: try: - connection.replace_route( - aws_retry=True, - RouteTableId=route_table['RouteTableId'], - **route_spec) + connection.replace_route(aws_retry=True, RouteTableId=route_table['RouteTableId'], **route_spec) except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e: module.fail_json_aws(e, msg="Couldn't recreate route") for route_spec in route_specs_to_create: try: - connection.create_route( - aws_retry=True, - RouteTableId=route_table['RouteTableId'], - **route_spec) - except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e: + connection.create_route(aws_retry=True, RouteTableId=route_table['RouteTableId'], **route_spec) + except is_boto3_error_code('RouteAlreadyExists'): + changed = False + except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e: # pylint: disable=duplicate-except module.fail_json_aws(e, msg="Couldn't create route") return {'changed': bool(changed)}