From Notes Wiki
Jump to: navigation, search
Home > CentOS > CentOS 6.x > System Administration Tools > Ansible > Ansible tips and tricks > Convert list variable to comma separated list in ansible

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