Ansible revert back operation

I have three IPs (machines) listed in the inventory file.
I have to run the playbook in all the 3 mchines.
For eg., Lets consider I am deploying the application in all the 3 machines.
When the deployment fails in any of the machines it has to revert back the operations in all the 3 machines/(or to the machines where the deployment is completed) eventhough it is successfully deployed.
I have the revert_back playbook written seperately.

Is there any way in ansible to achieve this requirement?

Can anyone help me out in this requirement?

In my understanding you can use blocks to handle ay exception and rollback using rescue.

https://docs.ansible.com/ansible/latest/user_guide/playbooks_blocks.html

Regards,
Punit

Hi Preethi,

Ansible does not provide any functionality for global rollback but it does provide an option to handle errors at task level. As suggested by Punit, blocks and rescue can be used to handle errors and revert certain actions but those would only be limited to the host on which the task has failed.

To fulfill your requirement, you would need to write a separate task that reverses the action of the deploy task on all the hosts (even on the successful hosts) when the task has failed on any number of hosts.

You may use a playbook similar to the one below:

`