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.
NOTE This is similar to Kashyap's answer, but i needed a slightly different version: Using it to double quote each items in a bash array), eg. result should be:
SOME_LIST=( "Johnny" "Joey" "Dee Dee" "Tommy" )
projects/ansible/expand_list.yml
---
- hosts: localhost
connection: local
vars:
some_list:
- Johnny
- Joey
- Dee Dee
- Tommy
tasks:
- name: "Expand the ramones band members list."
template:
src: "templates/expand_list.conf.j2"
dest: "/var/tmp/ramones.conf"
projects/ansible/templates/expand_list.conf.j2
SOME_LIST=( "{{ '" "'.join(some_list) }}" )