include_vars look up files in wrong directory if used with local_action

I believe it is a bug, but since I am an ansible beginner I would like to check with someone before reporting - either for comfirmation or some indication that I am doing it the wrong way:

I am trying to load some variables from files in a role. The names of files are stored in a variable, in the same role. Thing is, I try to run the include_vars as a local_action.

roles/common/vars/main.yml:
`
x:

  • aaa
  • bbb
    `

roles/common/tasks/main.yml:

`

  • name: include vars w/ local_action
    local_action: include_vars “{{item}}.yml”
    with_items: “{{x}}”
    `

site.yml:

`

  • name: common stuff
    hosts: all
    gather_facts: no
    roles:
  • common
    `

This should, afaik, load the variables defined in files roles/common/vars/aaa.yml and roles/common/vars/bbb.yml. But when I runansible-playbook site.yml the files are searched in ./ instead of in roles/common/vars:

TASK [common: include vars w/ local_action] *********************
task path: /home/ansible/roles/dsv/tasks/main.yml:12
failed: [my.host → localhost] => (item=aaa) => {“failed”: true, “file”: “/home/ansible/aaa.yml”, “invocation”: {“module_args”: {“_raw_params”: “"aaa.yml"”}, “module_name”: “include_vars”}, “item”: “aaa”, “msg”: “Source file not found.”}

Is this an expected behaviour or a bug, taking into account that when I do the include_vars without the local_action everything works fine?

BTW, the above example is a test case I made to show the problem in a simple way. This error showed up in a real use case a lot more complex. I am using ansible 2.0.0.

Thanks in advance.

Paulo Suderio

Paulo,

Does 1.9.4 behave in the same "inconsistent" way?

include vars is ALWAYS a 'local' action, you don't need to add that
nor delegate_to: localhost, it works the same as a include,add_host,
etc, these are all actions done on the ansible master on behalf of the
inventory_hostname, there is not need to 'localize' them.

So this 'might' be a bug, as the local action should be ignored, but
might be changing the 'cwd' of the task and confusing the include
mechanism.

Brian,

I’m having the same problem on Ansible 2.0.2 without local action. I’m running on tower