Home ansible get the interface name by providing an IP address
Reply: 0

ansible get the interface name by providing an IP address

user777
1#
user777 Published in July 20, 2018, 1:20 am

I have two interfaces in machine(linux). One interface has been addressed and second is down without any IP. Now I would like to get the interface name matched with IP what I provide as value in ansible.

I was trying something like this:

    - name: interface name from provides IP
  set_fact:
    interface_name="{{ item }}"
  with_items:
     - "{{ ansible_interfaces | map('replace', '-','_') | list }}"
  when: hostvars[ansible_fqdn]['ansible_'~item]['ipv4']['address'] == PROVIDED_IP

It works good when all interfaces have IP address but problem is when one interface has no IP then I have error: 'dict object' has no attribute 'ipv4'

Is possible to get interface name without getting errors?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.311075 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO