I have very simple line in the template:
ip={{ip|join(\', \')}}
And I have list for ip:
ip:
- 1.1.1.1
- 2.2.2.2
- 3.3.3.
This will work :
ip={{ '\"' + ip|join('\", \"') + '\"' }}
A custom filter plugin will also work. In ansible.cfg uncomment filter_plugins and give it a path, where we put this
def wrap(list):
return [ '"' + x + '"' for x in list]
class FilterModule(object):
def filters(self):
return {
'wrap': wrap
}
in a file called core.py. Like this. Then you can simply use
ip|wrap|join(', ')
And it should produce comma seperated list with each ip wrapped in quotes.