By default, if a task fails on one server (Host A), Ansible stops working on that server but continues trying to finish the task on all your other servers (Host B, Host C, etc.).
When you set any_errors_fatal: true, you are telling Ansible: "If even one server fails this task, stop everything immediately on all servers."
Why use it?
It is used for "all-or-nothing" scenarios where you cannot afford to have your environment in a mixed state.
Database Migrations: If the migration fails on one node, you don't want the others to keep going and potentially corrupt the cluster.
Load Balancers: If you are taking servers out of a rotation and one fails to leave the pool, you might want to stop the whole process before you start shutting down services.
Where can you put it?
You can apply this at different levels of your code:
| Level | Scope |
| Play Level | Affects every task in that specific play. |
| Block Level | Affects only the group of tasks inside that specific block. |
| Task Level | Not typically supported directly on a single task (usually used at play/block level). |
Comparison of Scope Keywords
It is easy to get confused because several error-handling keywords can be used at the task level, but any_errors_fatal is an exception.
| Keyword | Task Level? | Block Level? | Play Level? |
ignore_errors | Yes | Yes | Yes |
failed_when | Yes | No | No |
any_errors_fatal | No | Yes | Yes |
ignore_unreachable | Yes | Yes | Yes |
No comments:
Post a Comment