Convert list variable to comma separated list in ansible

From Notes_Wiki
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Home > CentOS > CentOS 6.x > System administration tools > ansible > Ansible tips and tricks > Convert list variable to comma separated list in ansible

To convert list variable such as:

arguments: [ "value1", "value2", "value3" ]

to a command separate value in a template file use:

{% for arg1 in arguments %}  {{arg1}} {% if not loop.last %}, {% endif %} {% endfor %} 

Other way is:

{{ users|join(', ') }}

Learned from http://stackoverflow.com/questions/11974318/how-to-output-a-comma-delimited-list-in-jinja-python-template



Home > CentOS > CentOS 6.x > System administration tools > ansible > Ansible tips and tricks > Convert list variable to comma separated list in ansible