advanced Jinja config

Hi,

I need help with the bellow configuration in Jinja, I’m using a for loop to populate the hosts from a group defined in my inventory and that’s working good but what my application requires is a letter in front of every host in alphabetical order depending how many host numbers I have :

servers.ini :

[server-slaves]
server1.example.com
server2.example.com

server3.example.com

config.conf.j2 :

slaves_hosts={% for host in groups[‘server-slaves’] %}

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

output :

slaves_hosts=server1.example.com,server2.example.com,server3.example.com

desired output

slaves_hosts=a:server1.example.com,b:server2.example.com,c:server3.example.com

This is possible in Chef, any idea if I can do the same in Ansible and how ?

Thanks in advance.

There might be a different way, but here is one that I can think of:

{% set letters = cycler(*‘abcdefghijklmnopqrstuvwxyz’[:]) %}
slave_hosts={% for host in slaves %}{{ letters.next() }}:{{ host }}{% if not loop.last %},{% endif %}{% endfor %}

This creates a ‘cycler’ with the lowercase letters of the english alphabet, and cycles through them on each iteration of the for loop.

You save my day Matt, thank you so much .