The meta module with clear_host_errors can be used to clear fatal and fail errors.
The ansible-doc meta command can be used to show the Ansible documention on the meta module.
For example, let's say you have a playbook that uses the shell module to ping managed nodes (e.g. target systems).
---
- hosts: all
tasks:
- shell: "ping -c1 {{ inventory_hostname }}"
register: out
- debug:
msg: "{{ out.rc }}"
The following should be produced. Notice that the shell TASK returned that server2.example.com was unreachable, and then server2.example.com was not processed in the subsequent debug task.
PLAY [all]
TASK [Gathering Facts]
ok: [server1.example.com]
ok: [server2.example.com]
TASK [shell]
changed: [server1.example.com]
fatal: [server2.example.com]" UNREACHABLE! => {"msg": "Failed to connect to the host via ssh: ssh: connect to host server1.example.com port 22: Connection refused", "unreachable": true}
TASK [debug]
ok: [server1.example.com] => {
"msg": "0"
}
PLAY RECAP
server1.example.com : ok=2 changed=1 unreacable=0 failed=0
server1.example.com : ok=2 changed=1 unreacable=0 failed=0
The meta module with clear_host_errors will change this behavior, so that server2.example.com is processed in the subsequent debug task.
---
- hosts: all
tasks:
- shell: "ping -c1 {{ inventory_hostname }}"
register: out
- meta: clear_host_errors
- debug:
msg: "{{ out.rc }}"