Changing Last item in Host Group for Template

Hello,

I have got situation, where I needed to change last item in the host group for template.
{% for host in groups[‘application_srv’] %}

{% if groups[‘application_srv’].index(inventory_hostname) == -1 %}
          'app@{{ hostvars[host]['ansible_fqdn'] }}'
{% else %}
          'app@{{ hostvars[host]['ansible_fqdn'] }}',
{% endif %}
{% endfor %}



But this does not working. Maybe someone can, to use host_group item and then loop thru the index as last one

You should explain what you are trying to do so we don't have to guess.
So what you are trying to do is to not have a comma after the last item?

If so Jinga has many loop variables[1] you can use inside a for loop.
The one you are looking for is loop.last.

{% if not loop.last %},{% endif %}

[1] http://jinja.pocoo.org/docs/2.10/templates/#for