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
- Group Tasks with block
- Try / Catch with rescue & always
- Control Failure: failed_when & ignore_errors
- Custom Assertions with the fail Module