Upcoming versions of NetBSD will print the network prefix in CIDR
notation instead of as a hex subnet mask. This currently causes Ansible
to choke on ifconfig output there. See:
http://cvsweb.netbsd.org/bsdweb.cgi/src/sbin/ifconfig/af_inet.c.diff?r1=1.22&r2=1.23&only_with_tag=MAIN&f=h
This fixes it for me. I had never even looked at Ansible code before
today, let alone debugged it, so I'm sure there are better ways.
diff --git a/lib/ansible/module_utils/facts/network/generic_bsd.py b/lib/ansible/module_utils/facts/network/generic_bsd.py
index 212c842f43..30e7f5f726 100644
--- a/lib/ansible/module_utils/facts/network/generic_bsd.py
+++ b/lib/ansible/module_utils/facts/network/generic_bsd.py
@@ -198,13 +198,18 @@ class GenericBsdIfconfigNetwork(Network):
# inet alias 127.1.1.1 netmask 0xff000000
if words[1] == 'alias':
del words[1]
- address = {'address': words[1]}
+ if re.search('/', words[1]):
+ address = {'address': words[1].split('/')[0]}
+ address['netmask'] = socket.inet_ntoa(
+ struct.pack('!I', ( 1 << 32 ) - (1 << ( 32 - int(words[1].split('/')[1])))))
+ else:
+ address = {'address': words[1]}
# deal with hex netmask
if re.match('([0-9a-f]){8}', words[3]) and len(words[3]) == 8:
words[3] = '0x' + words[3]
if words[3].startswith('0x'):
address['netmask'] = socket.inet_ntoa(struct.pack('!L', int(words[3], base=16)))
- else:
+ elif not address['netmask']:
# otherwise assume this is a dotted quad
address['netmask'] = words[3]
# calculate the network