Passing variables to template file in template module

40 views
Skip to first unread message

Jérémy Judéaux

unread,
Jul 10, 2015, 12:02:31 PM7/10/15
to ansible...@googlegroups.com
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.

Brian Coca

unread,
Jul 10, 2015, 10:18:51 PM7/10/15
to ansible...@googlegroups.com
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

Jérémy Judéaux

unread,
Jul 13, 2015, 4:12:03 AM7/13/15
to ansible...@googlegroups.com
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


Reply all
Reply to author
Forward
0 new messages