In this tutorial, we will learn to ignore error in ansible playbook.
While Executing play book if any error occurred in a task. Remaining tasks will get ignored
Some Cases we want to ignore the error. Ansible provide option to ignore error on Exception handling
below is the Syntax to ignore error in ansible playbook
Syntax
ignore_errors: yes
Sample playbook
---
- name: Network Getting Started First Playbook
gather_facts: false
hosts: all
tasks:
- name: Make a directory
shell: "mkdir sample"
- name: Make another directory with same name
shell: "mkdir sample"
ignore_errors: yes
- name: Make another directory with another name
shell: "mkdir demo"
ignore_errors: yes
Output
fatal: [127.0.01]: FAILED! => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"}, "changed": true, "cmd": "mkdir sample", "delta": "0:00:00.008711", "end": "2020-02-21 10:23:37.305132", "msg": "non-zero return code", "rc": 1, "start": "2020-02-21 10:23:37.296421", "stderr": "mkdir: cannot create directory ‘sample’: File exists", "stderr_lines": ["mkdir: cannot create directory ‘sample’: File exists"], "stdout": "", "stdout_lines": []}
...ignoring
In the above example. we are trying to make a duplicate directory which will occur an error. So we used ignore_errors command to ignore the error and to proceed further
we can see the <span class="token punctuation">..</span>.ignoring
Reference
https://docs.ansible.com/ansible/latest/user_guide/playbooks_error_handling.html
Related Articles
ignore warning message in ansible