# How to use ignore\_errors with include statement ?

**URL:** <https://forum.ansible.com/t/how-to-use-ignore-errors-with-include-statement/23338>\
**Category:** Ansible Project\
**Created:** [December 27, 2016, 11:39pm UTC](https://forum.ansible.com/t/how-to-use-ignore-errors-with-include-statement/23338 "2016-12-27T23:39:31Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cann](https://avatars.discourse-cdn.com/v4/letter/c/2bfe46/32.png) [@Cann](https://forum.ansible.com/u/Cann)\
**Post date:** [December 27, 2016, 11:39pm UTC](https://forum.ansible.com/t/how-to-use-ignore-errors-with-include-statement/23338/1 "2016-12-27T23:39:31Z")

</div>

Hello all,

I have dynamic variable that includes specific playbook during run time. I don’t want my ansible to fail if variable is not defined.

I tried to use ignore\_errors statement but it does not work for some reason.

Example:

`

# add worker specific settings

- include: tasks/{{ worker\_type }}.yml  
ignore\_errors: yes  
`

Error message:

`  
TASK [ServerSetup/server : include] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
fatal: [35.166.201.62]: FAILED! =\> {“failed”: true, “reason”: “the file\_name ‘/Users/admin/dev/ansible/tasks/image-worker.yml’ does not exist, or is not readable”}

`

I am running ansible 2.2

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [December 28, 2016, 1:12am UTC](https://forum.ansible.com/t/how-to-use-ignore-errors-with-include-statement/23338/2 "2016-12-28T01:12:18Z")

</div>

> I have dynamic variable that includes specific playbook during run time. I  
> don't want my ansible to fail if variable is not defined.
> 
> I tried to use ignore\_errors statement but it does not work for some  
> reason.
> 
> Example:
> 
> # add worker specific settings  
> - include: tasks/{{ worker\_type }}.yml  
> &nbsp;&nbsp;ignore\_errors: yes

- include: tasks/{{ worker\_type }}.yml  
&nbsp;&nbsp;&nbsp;when: worker\_type is defined

> Error message:
> 
> TASK [ServerSetup/server : include]  
> \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
> fatal: [35.166.201.62]: FAILED! =\> {"failed": true, "reason": "the  
> file\_name '/Users/admin/dev/ansible/tasks/image-worker.yml' does not exist,  
> or is not readable"}

This message indicate that the variable is defined but the file doesn't exist.  
So what is it that you actually want?

---

<div class="post-metadata">

**Author:** ![Cann](https://avatars.discourse-cdn.com/v4/letter/c/2bfe46/32.png) [@Cann](https://forum.ansible.com/u/Cann)\
**Post date:** [December 28, 2016, 2:38am UTC](https://forum.ansible.com/t/how-to-use-ignore-errors-with-include-statement/23338/3 "2016-12-28T02:38:50Z")

</div>

Hello, @Kai Stian Olstad,

I am not sure what is not clear about my question. As title indicates: “How to use ignore\_errors with include statement ?”

I want ansible to ignore this error. I use “ignore\_errors: yes” but it fails anyways.

I hope this clarifies.

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [December 29, 2016, 11:52am UTC](https://forum.ansible.com/t/how-to-use-ignore-errors-with-include-statement/23338/4 "2016-12-29T11:52:12Z")

</div>

> I am not sure what is not clear about my question. As title indicates: "How  
> to use ignore\_errors with include statement ?"

In your subject you have one thing, but in the mail you are talking about undefined variables, and in the example you av including a file that doesn't exist.

> I want ansible to ignore this error. I use "ignore\_errors: yes" but it  
> fails anyways.

ignore\_errors only work on task that return a exit code, include is just a directive to include tasks.  
Ignore\_error will be applied to every task in the include file, but it will not work on include when you are including a file that doesn't exist.

---

<div class="post-metadata">

**Author:** ![Cann](https://avatars.discourse-cdn.com/v4/letter/c/2bfe46/32.png) [@Cann](https://forum.ansible.com/u/Cann)\
**Post date:** [December 30, 2016, 10:00pm UTC](https://forum.ansible.com/t/how-to-use-ignore-errors-with-include-statement/23338/5 "2016-12-30T22:00:41Z")

</div>

Thank you very much for clarification Kai

You’re awesome \<3
