Reputation: 129
I have this variable:
amq_ping_hosts:
- "10.1.1.1"
- "10.1.1.2"
- "10.1.1.3"
- "10.1.1.4"
and I want to create variable with a comma separated string:
ping_hosts: 10.1.1.1,10.1.1.2,10.1.1.3.10.1.1.4
I tried this:
- name: "set fact ping_hosts"
set_fact:
ping_hosts: "{{ ping_hosts }} ',' {{ item }}"
loop: "{{ amq_ping_hosts }}"
but ping_hosts is an undefined variable
Upvotes: 1
Views: 677
Reputation: 68034
Use join. The tasks below
- set_fact:
ping_hosts: "{{ amq_ping_hosts|join(',') }}"
- debug:
var: ping_hosts
give
ping_hosts: 10.1.1.1,10.1.1.2,10.1.1.3,10.1.1.4
Upvotes: 3
Reputation: 6685
you can use join
function from python:
tasks:
- set_fact:
ping_hosts: "{{ ','.join(amq_ping_hosts) }}"
- debug:
var: ping_hosts
Upvotes: 1