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.
try:
- hosts: localhost
tags: s20
gather_facts: no
vars:
ip:
- 1.1.1.1
- 2.2.2.2
- 3.3.3.3
joined_ip: "'{{ \"', '\".join(ip)}}'"
tasks:
- debug: msg="(ip={{joined_ip}})"
PS: ansible supports a bit of python code execution within {{}}
, which is what i'm misusing here.
Following worked for me
('{{ iplist | join('\',\'') }}')
Ex:
Inventory
[ips]
1.1.1.1
2.2.2.2
3.3.3.3
#cat temp.sh.j2
"ips": (ip='{{ groups['zoo'] | join('\',\'') }}')
result:
#cat temp.sh
"ips": (ip='1.1.1.1','2.2.2.2','3.3.3.3')
Hope it would help someone.