Ansible - End all plays in a playbook using any_errors_fatal

by
Jeremy Canfield |
Updated: June 01 2025
| Ansible articles
There are a few different ways to "end" plays.
- end_play will end a play for all hosts
- end_host will end a play for certain hosts
- any_errors_fatal will end all plays in a playbook (this article)
end_play and ansible.builtin.fail are also similar, but not exactly the same.
- end_play will end the play for all hosts and will consider the play "failed"
- ansible.builtin.fail will end the play for certain hosts and will NOT consider the play "failed"
For example, let's say you have the following playbook which uses any_error_fatal: true in the first play and also has ansible.builtin.fail in the first play.
---
- name: first play
hosts: all
any_errors_fatal: true
tasks:
- name: fail all plays for server1
ansible.builtin.fail:
msg: failing all plays for server1
when: inventory_hostname == 'server1'
- name: second play
hosts: all
tasks
- ansible.builtin.debug:
msg: this is a task in the second play
...
Running this playbook should return something like this, where the second play is never invoked.
TASK [fail all plays for server2]
[ERROR]: Task failed: Action failed: failing all plays for server1
5 - name: fail all plays for server1
^ column 5
fatal: [server1.example.com]: FAILED! => {"changed": false, "msg": "failing all plays for server1"}
PLAY RECAP *********************************************************************
server1.example.com : ok=18 changed=3 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0
Did you find this article helpful?
If so, consider buying me a coffee over at