rollback of tasks

I am trying to find out the best practice for writing modules that are composed of multiple config steps.

For example, a module when it executes with given input might go through a sequence of API requests, checking for errors at every step.

If at some intermediate step the return value is a 404 then the entire task is considered to have failed (json_exit(error message)).

Now because all the config steps up till the error have succeeded, the system is left in a new state that is neither the starting state nor the intended target state.

Is the only answer in this case to develop such modules with rollback built into them?

https://docs.ansible.com/ansible/playbooks_blocks.html has some info about
the block/rescue/always construction, which can do a lot of what you're
talking about.

There's at least one significant bug with multiple blocks or tasks after
blocks, https://github.com/ansible/ansible/issues/20736 has more details.
Can be worked around, but good to be aware of.

                                      -Josh (jbs@care.com)

(apologies for the automatic corporate disclaimer that follows)

This email is intended for the person(s) to whom it is addressed and may contain information that is PRIVILEGED or CONFIDENTIAL. Any unauthorized use, distribution, copying, or disclosure by any person other than the addressee(s) is strictly prohibited. If you have received this email in error, please notify the sender immediately by return email and delete the message and any attachments from your system.