I need to convert the following yaml dictionary into comma-separated list of key=value pairs
nodes:
node1: 192.168.56.11
node2: 192.168.56.12
so it becomes
node1=192.168.56.11,node2=192.168.56.12
In Python I would do it with a simple list comprehension and then join the list:
','.join([ k+'='+v for k,v in nodes.items()])
I cannot figure out how to do it elegantly in an Ansible template, though. I can do it with for
loop, of course, but it leaves the trailing comma. My best shot so far:
{% for k,v in nodes.items() %}{{k}}={{v}}{% if not loop.last %},{% endif %}{% endfor %}
Am I overlooking something?