include file through variable.

69 views
Skip to first unread message

Nico K.

unread,
Jul 27, 2014, 5:08:20 PM7/27/14
to ansible...@googlegroups.com
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.

Michael DeHaan

unread,
Jul 28, 2014, 10:04:55 AM7/28/14
to ansible...@googlegroups.com
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.




--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/cb5b1d34-7f80-4377-8206-e6d5be088c19%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Nico K.

unread,
Jul 28, 2014, 11:55:07 PM7/28/14
to ansible...@googlegroups.com
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.

Op maandag 28 juli 2014 16:04:55 UTC+2 schreef Michael DeHaan:

Michael DeHaan

unread,
Jul 29, 2014, 8:55:03 AM7/29/14
to ansible...@googlegroups.com
This is already fixed on devel and we're looking at releasing 1.7 in a couple of weeks.



Michael DeHaan

unread,
Jul 29, 2014, 8:55:28 AM7/29/14
to ansible...@googlegroups.com
The underlying problem is that parameters quoted to an "include" line were keeping quotes, which the above fixes.


Reply all
Reply to author
Forward
0 new messages