include_vars in ansible 2.0

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.

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

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.

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