ec2_vpc_route_table to delete a given subnet

Hello all,

I am using the ec2_vpc_route_table module and am able to create the route table, as well as adding more subnets with the “subnets”, “purge_subnets” and “lookup” parameters. I however have been unable to determine how to remove a subnet from an existing route_table. The only solution I have found is to query and get all the existing subnets and pass them in with purge_subnets=true on a second call.

I am hoping I am overlooking, or perhaps missing an example, of how I can do one call that would allow me to delete a given subnet from an existing route_table.

This works to add,

profile: “{{ aws_profile }}”
vpc_id: “{{ vpc_id }}”
state: present
region: us-east-1

lookup: id

route_table_id: rtb-0000000000000

subnets:

  • subnet-0418000000000000

purge_routes: no
purge_subnets: no
purge_tags: no

I was hoping adding state: absent would work, but that attempts to delete the route_table instead of the subnet.

Thanks!

https://docs.ansible.com/ansible/latest/modules/ec2_vpc_route_table_module.html

I think this is how it is supposed to work.
You define which subnets there should be, and the module will take care of that.
The only choice is whether to purge subnets that aren't in your desired list.

Dick