include file through variable.

Hi,

I just updated to the latest and greatest revision and since the update I can no longer perform an include of a file defined through a variable.

For instance:

  • include: “{{ file }}.yml”
    when: file is defined

now throws the following error:

ERROR: file could not read: /path/to/file/“file”.yml

(note the double quotes that are added around ‘file’).

-Nico.

So this still works and we know because we have an integration test for it, but what you have with the “when: file is defined” has NEVER worked.

What happens with an include is the conditional is applied to all tasks in the include, it cannot be used to decide to include something or not, because the same tasks (with different variable contexts of course) get applied to all hosts.

Hi Michael,

It’s funny you say that, since I’ve been running this playbook for a while and ever since the update it started failing; it might very well be that the ‘when’ never did what I expected it to do though.

However, there is a clear change in behavior, further investigation shows that previously:

roles/x/tasks/main.yml:

  • include: …/…/y/tasks/main.yml name=“sometask”

roles/y/tasks/main.yml

  • include: “{{ name }}.yml”

would evaluate to “sometask.yml”, however now it evaluates to “sometask”.yml (Mind the quoting)
When you remove the quotes around variable passed in (name=sometask) it does seem to work again.

-N.

This is already fixed on devel and we’re looking at releasing 1.7 in a couple of weeks.

https://github.com/ansible/ansible/commit/6e814566de36558a52bcb19ab4231e572cf5a63b

The underlying problem is that parameters quoted to an “include” line were keeping quotes, which the above fixes.