1

From what I can tell, ansible only does error handling at the level of tasks, which is really not enough for what I want it to be able to do.

Specifically, my use case is a run-of-the-mill deployment, so what I need to do is:

  • stop the server
  • backup necessary resources
  • try to deploy (which involves a large number of tasks which must occur in order)
    • if that failed, rollback to the previous version (which, again, is a bunch of tasks with a strict ordering)
  • start the server

All that's fine and dandy, except the error-handling approach which I hoped would work...

- include: deploy.yml
  ignore_errors: yes
  register: deploy
- include: rollback.yml
  when: deploy | failed

...Doesn't.

Now, I can understand why it wouldn't- the include task would just test whether it could include the file, not whether the file it included could run to completion. I've made my peace with that.

Unfortunately, this leaves me in something of a pickle. The automatic error checking of every operation, combined with the library of high-level operations, is the entire reason I use ansible. But, in the absence of a mature recovery mechanism, being notified of failure ceases to be useful.

Anyone have (sane) workarounds? I could add a handler to every single task under that include and try to make it work that way, but... Really? That can't be the solution- or, rather, I can't continue to have faith in humanity and allow for that to be a solution.

2
  • I suppose I could just make two calls to ansible-playbook within a bash script, but I thought I should check whether there was a pure ansible way of doing things, first. Jan 13, 2016 at 15:39
  • Here's what you really want for recent versions of ansible: docs.ansible.com/ansible/playbooks_blocks.html
    – eco
    Jun 2, 2017 at 23:01

1 Answer 1

5

http://www.ansible.com/blog/ansible-2.0-launch

Blocks introduce the concept of exception handling to playbooks, and were modeled after the try/except/finally structure of Python (and many other languages). This eases development of playbooks and tasks, where task failures can be caught and dealt with in a single playbook much more simply than before.

1
  • 1
    Good to know... Yet another reason to switch to version 2. <grumble> Well, that, and the fact that they don't version the documentation. </grumble> Jan 13, 2016 at 16:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .