Hi,
I think you are almost there.
You almost certainly don't want to have 'with_items' on your template
call. This will try to template once for each item in "{{parameters}}".
But "{{parameters}}" is already a list of things, and is going to be
available to use in the template as a list, so I think you just need to
make your template like this
{% item for in parameters %}
{ item.sitename }}-test,{{ item.sitename }} description
{% endfor %}
That should loop through "{{parameters}}" and put each templated item onto
a new line I think (not tested).
Hope this helps,
Jon
On Tuesday, April 11, 2017 at 1:59:54 PM UTC+1, Jeffrey Ward wrote:
>
> Hi,
>
>
> I am new to ansible and new to the form.
>
> I am wondering how to loop through a template
>
> my template looks like this
>
>
> { item.sitename }}-test,{{ item.sitename }} description
>
> and my variables look like this
>
> ---
> parameters:
> - { sitename: testsite1 }
> - { sitename: testsite2 }
>
> my Task looks like this
>
> ---
> - name: Lines Templates
> template: src=test.j2 dest=../ansible/configurations/test.csv
> with_items: "{{ parameters }}"
>
> this works but I only get the one line of the last entry with looks like
> this
>
> testsite2-test,testsite2 description
>
>
> But what I am tring to get is this
>
>
> testsite1-test,testsite1 description
> testsite2-test,testsite2 description
>
>
> I have been looking and reading the Jinga2 Templates doc but truble
> finding which {% for in %} to use
>
> if some one could point me to the right direction that would be great.
>
>
> Jeff
>
>
>
>
>
>
>
>
>
--
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/d98d9a55-11b4-433e-84a2-6ea88acaa808%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.