Discussion:
[ansible-project] Passing variables to template file in template module
Jérémy Judéaux
2015-07-10 15:37:53 UTC
Permalink
Hi,

I have a template called in a loop. In order to improve readability and
reusability, I'd like to avoid any {{item}}, {{item.0}} or
{{item.1.something}} in my template file.

According to issue #4546, this doesn't seem possible. There is no
documentation about this on the template module page.
I tried like the following, which is also not working:

- template: src=src.j2 dest=/tmp/dest
vars:
index: "{{ item.0 }}"
thing: "{{ item.1 }}"
with_indexed_items: things_collection


Am I missing something ? Should I open a feature request for this ?

Thanks.
--
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-project+***@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/5efadac9-c009-4bd8-9b60-3bc2ce73739d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Brian Coca
2015-07-11 02:18:48 UTC
Permalink
I'm not sure what you are asking for here, things_collection is passed
to your template as are all other vars defined in the play and for the
host, there is no need to put it in with_ if you just want to directly
access the var already.
--
Brian Coca
--
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-project+***@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/CAJ5XC8%3D8RQ7BhWMKLFDaj3-ffgM3E%2Bawm%3D1jJCby1t0YOj7Sbg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Jérémy Judéaux
2015-07-13 08:12:02 UTC
Permalink
I actually want one file per item in the collection, should have written
the example this way:

- template:
src: src.j2
dest: "/tmp/dest-{{ item.0 }}"
vars:
index: "{{ item.0 }}"
thing: "{{ item.1 }}"
with_indexed_items: things_collection
Post by Brian Coca
I'm not sure what you are asking for here, things_collection is passed
to your template as are all other vars defined in the play and for the
host, there is no need to put it in with_ if you just want to directly
access the var already.
--
Brian Coca
--
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-project+***@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/8219744e-c113-4f8e-b47d-d0d05e2b5542%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...