How to use ignore_errors with include statement ?

1,380 views
Skip to first unread message

Cann

unread,
Dec 27, 2016, 6:39:31 PM12/27/16
to Ansible Project
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

Kai Stian Olstad

unread,
Dec 27, 2016, 8:12:44 PM12/27/16
to ansible...@googlegroups.com
On 28. des. 2016 00:39, Cann wrote:
> 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

- include: tasks/{{ worker_type }}.yml
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?


--
Kai Stian Olstad

Cann

unread,
Dec 27, 2016, 9:38:51 PM12/27/16
to Ansible Project, ansible-pr...@olstad.com
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.

Kai Stian Olstad

unread,
Dec 29, 2016, 6:53:04 AM12/29/16
to ansible...@googlegroups.com
On 28. des. 2016 03:38, Cann wrote:
> 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.


--
Kai Stian Olstad

Cann

unread,
Dec 30, 2016, 5:00:41 PM12/30/16
to Ansible Project, ansible-pr...@olstad.com
Thank you very much for clarification Kai

You're awesome <3
Reply all
Reply to author
Forward
0 new messages