0Pricing
Ansible Academy · Lesson

Try / Catch with rescue & always

Recover gracefully from failures.

Blocks Get a Safety Net

Pair a block with rescue and always to get try, catch and finally for your tasks. Failures become recoverable. 🛟

The rescue Section

If any task in the block fails, Ansible jumps to rescue and runs those tasks instead, like a catch clause.

- block:
    - ansible.builtin.command: /opt/risky-step
  rescue:
    - ansible.builtin.debug:
        msg: "Step failed, recovering"

All lessons in this course

  1. Group Tasks with block
  2. Try / Catch with rescue & always
  3. Control Failure: failed_when & ignore_errors
  4. Custom Assertions with the fail Module
← Back to Ansible Academy