linux networking facts: Provide IPv4 prefix (#77193)

For IPv6 addresses, Ansible already provides the prefix length for IP
addresses in the `prefix` fact. This patch adjusts the facts for IPv4
addresses to also contain the prefix length in the prefix fact. This
makes it easier to use the facts consistently when the CIDR notation is
needed.

Signed-off-by: Till Maas <opensource@till.name>
pull/77342/head
Till Maas 3 years ago committed by GitHub
parent 14098d9b04
commit bf00a14f91
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,3 @@
---
minor_changes:
- facts - report prefix length for IPv4 addresses in Linux network facts.

@ -192,7 +192,9 @@ class LinuxNetwork(Network):
interfaces[iface]['ipv4'] = {'address': address,
'broadcast': broadcast,
'netmask': netmask,
'network': network}
'network': network,
'prefix': netmask_length,
}
else:
if "ipv4_secondaries" not in interfaces[iface]:
interfaces[iface]["ipv4_secondaries"] = []
@ -201,6 +203,7 @@ class LinuxNetwork(Network):
'broadcast': broadcast,
'netmask': netmask,
'network': network,
'prefix': netmask_length,
})
# add this secondary IP to the main device
@ -213,6 +216,7 @@ class LinuxNetwork(Network):
'broadcast': broadcast,
'netmask': netmask,
'network': network,
'prefix': netmask_length,
})
# NOTE: default_ipv4 is ref to outside scope
@ -221,6 +225,7 @@ class LinuxNetwork(Network):
default_ipv4['broadcast'] = broadcast
default_ipv4['netmask'] = netmask
default_ipv4['network'] = network
default_ipv4['prefix'] = netmask_length
# NOTE: macaddress is ref from outside scope
default_ipv4['macaddress'] = macaddress
default_ipv4['mtu'] = interfaces[device]['mtu']

Loading…
Cancel
Save