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?

It will be helpful for me if anyone could guide me in achieving this requirement.

Instead of reverting the operation, it might be better to instruct ansible to perform the operation serially rather than on parallel. Then if the operation fails on one, it won’t run on the others, and you have to run the revert_back playbook manually.

You can use a block rescue: to run the revert tasks automatically, but this will consider the run a success, so you’ll also need to include a custom failed: tak in your block to prevent other systems from being modified.,