- hosts: all name: get group ips in one line gather_facts: false vars: all_servers_ip: "{{groups['all'] | map('extract',hostvars,['ansible_ssh_host']) | join(',') }}" tasks: - debug: msg: "{{all_servers_ip}}"