ansoble facts for ipv4

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
    link/ether 52:54:00:c0:ff:f2 brd ff:ff:ff:ff:ff:ff
    inet 91.212.YYY.XXX/24 brd 91.212.112.255 scope global eth1
    inet 91.212.YYY.ZZZ/32 scope global eth1

lb01.DDDD.SS | success >> {
    "ansible_facts": {
        "ansible_eth1": {
            "active": true,
            "device": "eth1",
            "ipv4": {
                "address": "91.212.YYY.ZZZ",
                "netmask": "255.255.255.255",
                "network": "91.212.YYYY.ZZZ"
            },
            "ipv6": [
                {
                    "address": "2001:67c:YYYY::XXXX",
                    "prefix": "64",
                    "scope": "global"
                },
                {
                    "address": "fe80::5054:ff:fec0:fff2",
                    "prefix": "64",
                    "scope": "link"
                }
            ],
            "macaddress": "52:54:00:c0:ff:f2",
            "module": "virtio_net",
            "mtu": 1500,
            "type": "ether"
        }
    },

  Peter

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.

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

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 brd 10.20.0.255 scope global eth3
inet 10.20.0.3/32 scope global eth3
inet 10.20.0.100/32 scope global eth3
inet 10.20.0.101/32 scope global eth3
inet 10.20.0.7/32 scope global eth3
inet 10.20.0.8/32 scope global eth3
inet 10.20.0.4/32 scope global eth3
inet 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”
},

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.