Jinja2 template variables to one line

Here's the solution that worked for me. I discovered that tweeks200's solution only works for 2 loops. This works regardless of the number of loops. Thanks to everyone here for the help.

elasticsearch_discovery_zen_ping_unicast_hosts={% for host in groups['tag_Function_logdb']  %}
{{ host }}:9300
{%- if not loop.last %},{% endif %}
{% endfor %}

I was able to get this working by putting the directive I wanted before loop and then using the loop.first and - whitespace control to format the comma separated list properly.

elasticsearch_discovery_zen_ping_unicast_hosts = {% for host in groups['tag_Function_logdb']  %}
{{ host }}:9300
{%- if loop.first %},{% endif %}
{% endfor %}

Tags:

Jinja2

Ansible