Are there any try-catch/rollback mode or error handler?

Hi guys!,

I would like to know if there are any ‘try - catch / rollback’ mode, I mean, I’m running a playbook with some tasks, when a given task crashes, I would like to run an external error recovery task ¿Can I do that?

Playbook example:

  • hosts: someofthem
    user: myuser
    tasks:
    -name: First task
    action: whatever
    onerror: clean_and_exit #this could be task (or a handler)
    -name: Second task
    action: whatever
    onerror: clean_and_exit


-name: clean_and_exit
action: do something…

Thanks in advance

You can add “ignore_errors” on a task and then use the “when” statement

  • action: shell foo
    register: foo_result
    ignore_errors: True

  • action: shell bar
    when: foo_result | failed

(The " | failed " is basically a wrapper around saying “foo_result.failed” but is also a bit more smart in some cases like when you get a list back)

Great! This works perfect for me.
Thanks you very much!