# ansoble facts for ipv4

**URL:** <https://forum.ansible.com/t/ansoble-facts-for-ipv4/12932>\
**Category:** Ansible Project\
**Created:** [June 10, 2013, 12:36pm UTC](https://forum.ansible.com/t/ansoble-facts-for-ipv4/12932 "2013-06-10T12:36:08Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hudec\_Peter](https://avatars.discourse-cdn.com/v4/letter/h/a87d85/32.png) [@Hudec\_Peter](https://forum.ansible.com/u/Hudec_Peter)\
**Post date:** [June 10, 2013, 12:36pm UTC](https://forum.ansible.com/t/ansoble-facts-for-ipv4/12932/1 "2013-06-10T12:36:08Z")

</div>

Hi

I have found one strange behaviour for ansible setup module on  
Linux/eth/ipv4 interfaces

In case the interface have more then 1 IPv4, only one is returned. On IPv6  
there is a array, on IPv4 only the hash.  
Is this OK?  
I'm trying to setup keep alive cluster, but is the keep alive is active,  
only the floating IP is returned ;(  
I'm using devel tree of ansible.  
If this is a bug I could fix it for Linux based class.

3: eth1: \<BROADCAST,MULTICAST,UP,LOWER\_UP\> mtu 1500 qdisc pfifo\_fast state  
UNKNOWN qlen 1000  
&nbsp;&nbsp;&nbsp;&nbsp;link/ether 52:54:00:c0:ff:f2 brd ff:ff:ff:ff:ff:ff  
&nbsp;&nbsp;&nbsp;&nbsp;inet 91.212.YYY.XXX/24 brd 91.212.112.255 scope global eth1  
&nbsp;&nbsp;&nbsp;&nbsp;inet 91.212.YYY.ZZZ/32 scope global eth1

lb01.DDDD.SS | success \>\> {  
&nbsp;&nbsp;&nbsp;&nbsp;"ansible\_facts": {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"ansible\_eth1": {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"active": true,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"device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bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"mtu": 1500,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"type": "ether"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}  
&nbsp;&nbsp;&nbsp;&nbsp;},

&nbsp;&nbsp;Peter

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [June 10, 2013, 12:40pm UTC](https://forum.ansible.com/t/ansoble-facts-for-ipv4/12932/2 "2013-06-10T12:40:36Z")

</div>

For a given interface device there is only one ipv4 address possible but it is possible to have multiple ipv4 addresses.

Notice the varying scopes.

This is working as designed and is not a bug.

---

<div class="post-metadata">

**Author:** ![Hudec\_Peter](https://avatars.discourse-cdn.com/v4/letter/h/a87d85/32.png) [@Hudec\_Peter](https://forum.ansible.com/u/Hudec_Peter)\
**Post date:** [June 10, 2013, 12:48pm UTC](https://forum.ansible.com/t/ansoble-facts-for-ipv4/12932/3 "2013-06-10T12:48:52Z")

</div>

Hi Michael,

> Notice the varying scopes.

I do not understand ?

Please could you tell me how can I get first/second/third IPv4 address on interface ethX?  
I have got also problem with the IP address order, at lie at for IPv6, where the floating is the first one, if the cluster node is active. But this is problem of the ‘ip addr show’ command which sorts it so ;(

Peter

---

<div class="post-metadata">

**Author:** ![Lorin\_Hochstein1](https://avatars.discourse-cdn.com/v4/letter/l/ce73a5/32.png) [@Lorin\_Hochstein1](https://forum.ansible.com/u/Lorin_Hochstein1)\
**Post date:** [June 11, 2013, 12:36am UTC](https://forum.ansible.com/t/ansoble-facts-for-ipv4/12932/4 "2013-06-11T00:36:38Z")

</div>

Linux supports multiple ipv4 addresses for a given interface device. In particular, OpenStack leverages this to implement floating IPs:

$ ip address show dev eth3  
5: eth3: \<BROADCAST,MULTICAST,UP,LOWER\_UP\> mtu 1500 qdisc mq state UP qlen 1000  
link/ether 78:49:f3:9c:1a:f5 brd ff:ff:ff:ff:ff:ff  
inet [10.20.0.2/24](http://10.20.0.2/24) brd 10.20.0.255 scope global eth3  
inet [10.20.0.3/32](http://10.20.0.3/32) scope global eth3  
inet [10.20.0.100/32](http://10.20.0.100/32) scope global eth3  
inet [10.20.0.101/32](http://10.20.0.101/32) scope global eth3  
inet [10.20.0.7/32](http://10.20.0.7/32) scope global eth3  
inet [10.20.0.8/32](http://10.20.0.8/32) scope global eth3  
inet [10.20.0.4/32](http://10.20.0.4/32) scope global eth3  
inet [10.20.0.9/32](http://10.20.0.9/32) scope global eth3

Ansible’s setup module only picks up the last one:

“ansible\_eth3”: {  
“active”: true,  
“device”: “eth3”,  
“ipv4”: {  
“address”: “10.20.0.9”,  
“netmask”: “255.255.255.255”,  
“network”: “10.20.0.9”  
},  
“macaddress”: “78:49:f3:9c:1a:f5”,  
“module”: “igb”,  
“mtu”: 1500,  
“type”: “ether”  
},

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [June 11, 2013, 12:48am UTC](https://forum.ansible.com/t/ansoble-facts-for-ipv4/12932/5 "2013-06-11T00:48:29Z")

</div>

Hmm, news to me. I stand corrected.

I thought OpenStack was doing floating IPs with multiple interfaces when I saw it. I was probably mistaken.

Patches to make this an array are welcome, although there are many people doing ansible\_eth3.ipv4.address, so it will need to return something like “extra\_addresses” as an array in this case or something similar to avoid breaking things.
