# include\_vars in ansible 2.0

**URL:** <https://forum.ansible.com/t/include-vars-in-ansible-2-0/20615>\
**Category:** Ansible Project\
**Created:** [February 18, 2016, 2:37pm UTC](https://forum.ansible.com/t/include-vars-in-ansible-2-0/20615 "2016-02-18T14:37:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marcus\_Furlong](https://avatars.discourse-cdn.com/v4/letter/m/f14d63/32.png) [@Marcus\_Furlong](https://forum.ansible.com/u/Marcus_Furlong)\
**Post date:** [February 18, 2016, 2:37pm UTC](https://forum.ansible.com/t/include-vars-in-ansible-2-0/20615/1 "2016-02-18T14:37:28Z")

</div>

Hi,

With ansible 2.0, should the following use of include\_vars give the error below?

# tree

├── roles  
│ └── common  
│ ├── tasks  
│ │ └── main.yml  
│ └── vars  
│ ├── Debian.yml  
│ └── default.yml

# cat roles/common/tasks/main.yml

- include\_vars: “{{ item }}”  
with\_first\_found:

- “{{ ansible\_os\_family }}.yml”

- “default.yml”

- package: name={{ bindutils\_package }} state=present

# cat roles/common/vars/default.yml

bindutils\_package: bind-utils

# cat roles/common/vars/Debian.yml

bindutils\_package: dnsutils

# ansible-playbook -i hosts site.yml

PLAY \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

TASK [setup] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [127.0.0.1]

TASK [include] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
included: /tmp/ansible-test/roles/common/tasks/main.yml for 127.0.0.1

TASK [include\_vars] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
fatal: [127.0.0.1]: FAILED! =\> {“failed”: true, “msg”: “ERROR! No file was found when using with\_first\_found. Use the ‘skip: true’ option to allow this task to be skipped if no files are found”}

PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
127.0.0.1 : ok=2 changed=0 unreachable=0 failed=1

Using strace, I can see it tries to access /tmp/vars/default.yml. This seems to be because roledir = None in lib/ansible/plugins/lookup/first\_found.py

roledir = variables.get(‘roledir’)

Is this the expected behaviour or am I using the module incorrectly?

Regards,  
Marcus.

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [February 25, 2016, 3:48am UTC](https://forum.ansible.com/t/include-vars-in-ansible-2-0/20615/2 "2016-02-25T03:48:11Z")

</div>

it is not an issue with the module, but with first found, which always looks in files/ not in vars/

---

<div class="post-metadata">

**Author:** ![Marcus\_Furlong](https://avatars.discourse-cdn.com/v4/letter/m/f14d63/32.png) [@Marcus\_Furlong](https://forum.ansible.com/u/Marcus_Furlong)\
**Post date:** [February 25, 2016, 7:44am UTC](https://forum.ansible.com/t/include-vars-in-ansible-2-0/20615/3 "2016-02-25T07:44:22Z")

</div>

> it is not an issue with the module, but with first found, which always looks in files/ not in vars/
> 
> ​this should work:​
> 
> ## with\_first\_found:
> 
> ​"vars/  
> {{ ansible\_os\_family }}.yml"
> 
> - "  
> ​vars/​  
> default.yml"

Unfortunately, that fails with the same error.

It looks like with\_first\_found now tries all directories:

if roledir is not None:

# check the templates and vars directories too,if they exist

for subdir in (‘templates’, ‘vars’, ‘files’):  
path = self.\_loader.path\_dwim\_relative(roledir, subdir, fn)  
if os.path.exists(path):  
return [path]

# if none of the above were found, just check the

# current filename against the current dir

path = self.\_loader.path\_dwim(fn)  
if os.path.exists(path):  
return [path]

However, ‘roledir’ = None for some reason, so we only check for the file in the current working directory.

Cheers,  
Marcus.

---

<div class="post-metadata">

**Author:** ![Rania\_Talbi](https://avatars.discourse-cdn.com/v4/letter/r/a6a055/32.png) [@Rania\_Talbi](https://forum.ansible.com/u/Rania_Talbi)\
**Post date:** [March 19, 2017, 9:27pm UTC](https://forum.ansible.com/t/include-vars-in-ansible-2-0/20615/4 "2017-03-19T21:27:41Z")

</div>

Hello, i was wondaring if u guys have found a solution for this issue
