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