Present VS Absent. Order of tasks is different when creating or deleting. Conditionals workaround?

Hi,

I hope someone here could shed some light on this. Below is a super simplified example using EC2 elements but this could happen with other elements obviously.

`

master_state: present

Create Subnet
state: {{ master_state }}

Create RoutingTable
state: {{ master_state }}

`

So this is fine, now we switch master_state to absent and script fails because RoutingTable needs to be erased first. (unless i get this script run in total reverse) is there a way to do this somehow? If I use Conditionals in combination with wait_for I could probably rely on order of tasks in file when state=present (normal) and when state=absent add to Subnet wait_for RoutingTable.id = null before trying to delete subnet.

Am I overcomplicating this? Is there an easy way to do this?

Peter.

Hi Peter,

I’m not quite following the full example and may need some information such as seeing your playbook. That all being said, as this is a bit more of a user question than a development of the project question, can you post further info over on ansible-project?

Thanks!