From 73d60e5c05455b773c2a9976b201346793a05fb2 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) --- .../fragments/359-fix-ec2_vpc_route_table.yml | 2 ++ plugins/modules/ec2_vpc_route_table.py | 14 +++++--------- 2 files changed, 7 insertions(+), 9 deletions(-) create mode 100644 changelogs/fragments/359-fix-ec2_vpc_route_table.yml diff --git a/changelogs/fragments/359-fix-ec2_vpc_route_table.yml b/changelogs/fragments/359-fix-ec2_vpc_route_table.yml new file mode 100644 index 00000000000..60ca36ba8a5 --- /dev/null +++ b/changelogs/fragments/359-fix-ec2_vpc_route_table.yml @@ -0,0 +1,2 @@ +bugfixes: + - ec2_vpc_route_table - catch RouteAlreadyExists error when rerunning same task twice to make module idempotent 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)}