On 29. juni 2016 22:26, Rory Schramm wrote:
I have a jinja template file that's iterating through the play hosts and
checking which site each hosts belongs to that should output like this:

192.168.1.1, 192.168.1.2, 192.168.1.3,

{%- for host in play_hosts %}{% if hostvars[host]['site'] == site %}{{ host
}}{% if not loop.last %}, {% endif %}{% endif %}{% endfor -%}

However, I'm getting this jinja output instead. It's not suppressing the
separator on the last loop item iteration...

192.168.1.1, 192.168.1.2, 192.168.1.3, 192.168.1.4,

Not tested, but something like this should work

{% set div = joiner(", ") %}
{% for host in play_hosts %}
{%- if hostvars[host]['site'] == site %}
{{ div }}{{ host }}
{%- endif %}
{% endfor %}

--
Kai Stian Olstad

--
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/57754D13.1040800%40olstad.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to