Difference between revisions of "Convert list variable to comma separated list in ansible"

From Notes_Wiki
(Created page with "<yambe:breadcrumb>Ansible_tips_and_tricks|Ansible tips and tricks</yambe:breadcrumb> =Convert list variable to comma separated list in ansible= To convert list variable such...")
 
m
 
Line 1: Line 1:
<yambe:breadcrumb>Ansible_tips_and_tricks|Ansible tips and tricks</yambe:breadcrumb>
[[Main Page|Home]] > [[CentOS]] > [[CentOS 6.x]] > [[System administration tools]] > [[Ansible|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:
To convert list variable such as:
Line 17: Line 16:


Learned from http://stackoverflow.com/questions/11974318/how-to-output-a-comma-delimited-list-in-jinja-python-template
Learned from http://stackoverflow.com/questions/11974318/how-to-output-a-comma-delimited-list-in-jinja-python-template
[[Main Page|Home]] > [[CentOS]] > [[CentOS 6.x]] > [[System administration tools]] > [[Ansible|ansible]] > [[Ansible tips and tricks]] > [[Convert list variable to comma separated list in ansible]]

Latest revision as of 11:48, 28 July 2022

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