I am passing a map
from terraform code to jinja2 for creating an ansible's hosts
file. In the hosts file, I am printing the map using the following code and it is working fine.
1. %{ for key, value in cat ~}
2. [${ key }]
3. %{ for v in value ~}
4. ${ v }
5. %{ endfor ~}
6. %{ endfor ~}
I am now trying to append :children
with the key but it is not working. I tried the following 04 ways of changing the line 2 in the above code but no luck. Following the link String concatenation in Jinja
Attempt 1:
[${ key|join(":children") }]
Attempt 2:
[${ key + ':children' }]
Attempt 3:
[${ key ~ ':children' }]
Attempt 4:
[${ key ~ ':children' ~}]
[${ key }:children]
that did the trick so the complete answer will be
%{ for key, value in cat ~}
[${ key }:children]
{ for v in value ~}
${ v }
%{ endfor ~}
%{ endfor ~}
Which will give us
[blue:children]
[green:children]