block, rescue and always
A structure that groups tasks in a block, runs the rescue tasks if one of them fails, and runs the always tasks either way.
In more detail
The block holds the ordinary work and can share one condition or privilege setting. rescue responds to a failure with recovery tasks; always handles cleanup or reporting that must happen in every outcome. A rescued failure lets the play continue and is counted as rescued in the recap, so decide deliberately whether continuing is safe and never let rescue hide a serious failure.
Related terms
- failed — The task result meaning the module ran on the host but could not do what the task asked.
- when condition — A task keyword holding an expression; the task runs on a host only if the expression is true there, and is reported as skipped otherwise.
- play recap — The summary at the end of a playbook run with one line per host counting tasks that were ok, changed, unreachable, failed, skipped, rescued and ignored.
Taught in
- Conditionals — Ansible Configuration Management at Scale
- Error Handling With Block, Rescue And Always — Ansible Configuration Management at Scale
- Variables And Where They Win: group_vars, host_vars And Play Vars — RHCE in Ansible (EX294): Automate Red Hat Systems
- Deploying Files: file, copy, lineinfile And blockinfile — RHCE in Ansible (EX294): Automate Red Hat Systems
- Loops: One Task, Many Items — RHCE in Ansible (EX294): Automate Red Hat Systems
- Handlers And Failure: notify, block, rescue And always — RHCE in Ansible (EX294): Automate Red Hat Systems
- Storage: Partitions, Volume Groups And Volumes Where The Disk Exists — RHCE in Ansible (EX294): Automate Red Hat Systems
- Jinja Templates: One File, A Different Text Per Host — RHCE in Ansible (EX294): Automate Red Hat Systems
- Drill: Storage Only Where The Disk Exists — RHCE in Ansible (EX294): Automate Red Hat Systems