on_failure error handlers - any ideas

Hi guys,

i have been using Ansible for about a month now, my use case has been managing a client’s cluster and moving all the infrastructure management to Ansible, so far i’v been loving it… but i was working on “new server deployment playbooks” and was faced with the fact that there is no universal way to handle errors… and we have to use ignore_erros/register/when which is fine for 1 or 2 tasks… but if you want for example to rollback a deployment of a new server on failure - delete the new instance - revert any changes on other hosts - remove it from loadbalancers… ect, you are gonna end up with one ugly and cluttered playbook…

so i thought i’d give it a shot and write something to mimic the behavior of notify handlers but for errors, and have it trigger them per task not at the end of the playbook “although this could be also done - it just didnt seem fitting for most use cases”

anyway i just did my first pull request : https://github.com/ansible/ansible/pull/8043

This is the first time i work with python and i loved it too, so thanks ansible for giving me the opportunity to finally get my hands dirty with python :slight_smile: but this also means that i might have done this the wrong way… or it could be improved.

i know this feature has been somewhat in demand, so i’d love to hear what you guys think, and how can we improve this?

Amr

Hi Amr,

Thanks very much for the contribution - we do have some specific ideas about what this would look like syntax wise and are planning on making something that requires a bit less boilerplate.

As such, we are probably going to close your pull request.

I have some ideas on what this should look like, but we want to get in a bit of refactoring first so I don’t think the time is to dive into this right now.

That being said, this should come, and is a good idea - just want something a bit more try/catch block like.

Hope this makes sense!