Ansible Error Handling with ignore_errors and block
By default a failed task removes that host from the rest of the play while the others carry on - which is neither obviously right nor obviously wrong until you have seen it. This shows the default, then ignore_errors, then deciding for yourself what counts as failure, then block/rescue/always, and finally stopping everything at once.
Plays and Playbooks Guide 16 of 45 Intermediate
- OSUbuntu 26.04 LTS
- ansible-core2.20.1
- Python3.14.4
- TimeAbout 17 min
rescue makes the play continue: a handled failure is counted as rescued rather than failed, and the play carries on afterwards. That is what makes block/rescue a real error-handling construct rather than a fancier ignore_errors.
| Server Name | IP Address | OS | Roles | CPU | RAM | HDD |
|---|---|---|---|---|---|---|
| ANS-CTL01 | 192.168.0.36 | Ubuntu 26.04 LTS | Ansible Control Node | 2 Core | 3 GB | 50 GB |
| ANS-A01 | 192.168.0.37 | Ubuntu 26.04 LTS | Managed Node (group: web) | 2 Core | 3 GB | 50 GB |
| ANS-B01 | 192.168.0.38 | Ubuntu 26.04 LTS | Managed Node (group: db) | 2 Core | 3 GB | 50 GB |
This guide includes
Use this when one failing task should not remove a host from the rest of the play. This matters because that removal is the default - and deciding for yourself what counts as failure is very often the real fix.
- seeing the default, where a failed task stops that host outright
- ignoring an error deliberately
- deciding yourself what counts as failure, since exit 1 is sometimes information
- using
block,rescueandalwaysfor real error handling - telling one host failing apart from all of them with
any_errors_fatal
Before you start
- A control node configured as shown in the first step.
- The session fails tasks deliberately on
ans-a01and changes nothing on either host.
-
The configuration this guide assumes
-
The default is to stop that host
-
Ignoring an error
-
Deciding yourself what counts as failure
-
block, rescue, always
-
One host failing versus all of them