# To list the target host's name and it's IP address using facts

**URL:** <https://forum.ansible.com/t/to-list-the-target-hosts-name-and-its-ip-address-using-facts/28516>\
**Category:** Ansible Project\
**Created:** [September 6, 2018, 2:57pm UTC](https://forum.ansible.com/t/to-list-the-target-hosts-name-and-its-ip-address-using-facts/28516 "2018-09-06T14:57:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pandu\_jh](https://avatars.discourse-cdn.com/v4/letter/p/3bc359/32.png) [@Pandu\_jh](https://forum.ansible.com/u/Pandu_jh)\
**Post date:** [September 6, 2018, 2:57pm UTC](https://forum.ansible.com/t/to-list-the-target-hosts-name-and-its-ip-address-using-facts/28516/1 "2018-09-06T14:57:57Z")

</div>

I need to list the target host’s name and IP address using set\_fact. Below is my playbook, but it’s giving error.

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: “{{ blockdevices }}”

Desired o/p is  
host1 : 172.168.1.21  
system2: 172.168.1.22

Anybody help me to fix this pls ? thanks in advance

---

<div class="post-metadata">

**Author:** ![Tchia04](https://avatars.discourse-cdn.com/v4/letter/t/fbc32d/32.png) [@Tchia04](https://forum.ansible.com/u/Tchia04)\
**Post date:** [September 6, 2018, 6:41pm UTC](https://forum.ansible.com/t/to-list-the-target-hosts-name-and-its-ip-address-using-facts/28516/2 "2018-09-06T18:41:40Z")

</div>

Assuming each host has only one ip address. how about this?

# for linux

# - name: display ansible\_default\_ipv4.address

# debug:

# var: ansible\_default\_ipv4.address

# for windows

- name: display ansible\_ip\_addresses  
debug:  
var: ansible\_ip\_addresses

- name: ansible\_hostname  
debug:  
var: ansible\_hostname

---

<div class="post-metadata">

**Author:** ![Pandu\_jh](https://avatars.discourse-cdn.com/v4/letter/p/3bc359/32.png) [@Pandu\_jh](https://forum.ansible.com/u/Pandu_jh)\
**Post date:** [September 7, 2018, 2:41am UTC](https://forum.ansible.com/t/to-list-the-target-hosts-name-and-its-ip-address-using-facts/28516/3 "2018-09-07T02:41:47Z")

</div>

Each host has multiple Ip's. And i need to list those Ip's.
