# Error handling

In 
Published 2022-12-03

This tutorial explains to you how to handle the errors in Ansible. This tutorial has an example as well.

In Ansible, is common thing to run the same playbook on parallel on many target. Sometimes, on a particular target you can receive an error. In this case, by default, Ansible stops the execution on that target, but continues to run the playbook on the other targets.

This behavior is when you have in the playbook something like this:

However, you can add the marked line in the playbook:

any_errors_fatal: true

In this case, when an error occurs, Ansible stops the execution of the playbook on all the targets.

You can handle the errors at the task level as well, like in the picture below:

  • ignore_errors: yes : any error you can have at this task is ignored

  • failed_when: "'Async' in return_result2.stdout" =: Ansible consider that this task failed if in the result of the task you find the word 'Async'