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



On Thursday, September 6, 2018 at 7:57:57 AM UTC-7, Pandu jh wrote:
>
> 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
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/4989dcae-ed19-4956-b37f-d96d72ec45b2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to