I need to save the target host's IP addresses to a file using set_fact. Below is my playbook, but it's giving output as a list.
hosts: all
tasks:
- set_fact:
data: "{{ ansible_all_ipv4_addresses }}"
- set_fact:
ip: "{{ data.split(',') }}"
- name: Show the devices
shell: echo {{ item }} >> /tmp/ips
with_items: "{{ ip }}"
output: ok: [system1] => { "data": [ "172.19.0.1", "172.18.0.1", "172.20.0.1", "172.17.0.1", "172.16.108.124", "10.0.41.117" ] }
cat /tmp/ips
[u'172.19.0.1', u'172.18.0.1', u'172.20.0.1', u'172.17.0.1', u'172.16.108.124', u'10.0.41.117']
Desired o/p is
172.168.1.21
172.168.1.22