Hi everyone,
(It’s more a jinja quesion but…)
Is there a way to convert a int to an alphabet letter (1 → a, 2 → b…)
More aesthetic than (with a filter and less useless variables):
`
letters: ‘abcdefghijklmnopqrstuvwxyz’
index: “{{ groups[‘group1’].index(inventory_hostname) }}”
index_letter: “{{ letters[index] }}”
`
Thanks
There is no existing filter that does this, but nothing prevents you
from writing one...
Something like this in your filters file:
def num2let(arg):
return 'abcdefghijklmnopqrstuvwxyz'[arg]
def num2let0(arg):
return 'abcdefghijklmnopqrstuvwxyz'[arg-1]
class FilterModule(object):
def filters(self):
return {
'num2let': num2let,
'num2let0': num2let0,
}
Then it's:
index: "{{ groups['group1'].index(inventory_hostname) | num2let0 }}"