Convert list variable to comma separated list in ansible

From Notes_Wiki
Revision as of 11:48, 28 July 2022 by Saurabh (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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