Ansible in a Minute · Ansible Core ·
Use any_errors_fatal to abort the play
Short answer
Set any_errors_fatal so a failure on one host stops the play on every host.
Subscribe for updates
Get an email whenever we publish new guides and blog posts. Unsubscribe anytime.
By subscribing you agree we may email you about Ansible in a Minute and related Level Up Labs updates. We store your address in the same lead sheet as our contact form.
Request
set any_errors_fatal and run a command that all hosts must succeed
Example
A quick heads-up: Every environment is different. Review and test this example before you run it on systems you care about.
---
- name: Disable Datacenter
hosts: all
gather_facts: false
any_errors_fatal: true
tasks:
- name: Disable Datacenter
ansible.builtin.command:
cmd: /path/to/disable_datacenter_command
register: disable_result
failed_when: disable_result.rc != 0
changed_when: disable_result.rc == 0How it works
By default a failed host is removed and the play continues on the rest. any_errors_fatal finishes the current batch, then stops the play on all hosts. Later tasks and plays do not run.
When to use it
- Disabling load balancers before maintenance when every host must succeed
- Stopping a multi-host change after the first failure
Requirements
- Ansible: >=2.14
Validation
- Syntax validated
- Not execution-tested
- Last verified 2026-09-18
Notes
You can set any_errors_fatal on a play or on a block. A rescue section can recover from a fatal error in that block. Use max_fail_percentage when you want to abort after a share of hosts fail, not after the first error.
Reference
- Aborting on the first error: any_errors_fatal (Ansible docs)
Built for every Ansible use case in every organization
BacklogZero can generate this kind of automation in your environment, just like it did here.