Ansible ignore_errors=True with Examples

ansible ignore_errors=True with examples

In ansible if anyone of the task fails then it will stop the the entire execution of playbook or role.

So to avoid this problem we use ingnore_errors=True

ignore_errors=True

Error Handling In ansible Playbooks

If you mention ignore_errors=true at the end of the task , if the task fails also still the playbook or role will run.  It will execute the next task without taking care of task success or failure. If the task failure also it will go for next task and if the task success also it will go for execution next task.

So if you mention ignore_errors=true in any task ansible will go for execution of next task with out taking care of the task result.

Ex:

Playbook or role:
[root@localhost ~]# cat ignore_errors.yml 
---
- hosts: localhost
  tasks:
  - name: Stop httpd if already running
    service: name=httkd state=stopped
    ignore_errors: True

  - name: Stop httpd if already running
    service: name=httpd state=stopped
Output Log:
[root@localhost ~]# ansible-playbook ignore_errors.yml 

PLAY [localhost] ***************************************************************

TASK [Gathering Facts] *********************************************************
ok: [localhost]

TASK [Stop httpd if already running] *********************************
fatal: [localhost]: FAILED! => {"changed": false, "msg": "Could not find the requested service httkd: host"}
...ignoring

TASK [Stop httpd if already running] *********************************
ok: [localhost]

PLAY RECAP *********************************************************************
localhost                  : ok=3    changed=0    unreachable=0    failed=0

here you can see that first task is failed but still ansible is executing second task and the playbook is not failed.

so here you can see in the log first task it is ignoring errors. and its going for second task.

ignore_errors=False

by default ansible will consider task as ignore_errors=False so no need to mention this, but mention ignore_errors=True depends on your requirements.

 

  • ansible ignore errors
  • Error Handling In Playbooks
  • Error Handling In ansible Playbooks
  • ansible ignore errors true
  • ignore errors false
  • playbook ignore errors ansible
  • Error Handling In ansible Playbooks
  • ansible role ignore errors
  • ignore_errors

Leave a Reply

Your email address will not be published. Required fields are marked *