There is a join
filter that we can use with lists to concatenate list elements with a given character.
If we are passing the list directly to with_items
or loop
then we can use loop_control to "extend" some more loop information to get ansible_loop.allitems
. Then this can be joined with the join
filter.
Example:
- set_fact:
foo: "{{ ansible_loop.allitems|join(',') }}"
loop:
- one
- two
- three
loop_control:
extended: true
Otherwise a more straightforward way is to define a variable with list and use join
filter on elements of that variable.
Example:
- set_fact:
foo: "{{ mylist|join(',') }}"
vars:
mylist:
- one
- two
- three
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…