Question:
I have very simple line in the template:
1 2 |
ip={{ip|join(', ')}} |
And I have list for ip:
1 2 3 4 5 |
ip: - 1.1.1.1 - 2.2.2.2 - 3.3.3.3 |
But application wants IPs with quotes (ip=’1.1.1.1′, ‘2.2.2.2’).
I can do it like this:
1 2 3 4 5 |
ip: - "'1.1.1.1'" - "'2.2.2.2'" - "'3.3.3.3'" |
But it is very ugly. Is any nice way to add quotes on each element of the list in ansible?
Thanks!
Answer:
Actually there is a very simple method to achieve this:
1 2 |
{{ mylist | map('quote') | join(', ') }} |
The filter map
iterates over every item and let quote
process it. Afterwards you can easily join
them together.