From d49cdb4b8480c4ffa7f4422cf1412c148cde82b3 Mon Sep 17 00:00:00 2001 From: Mark Goddard Date: Wed, 26 Jul 2017 17:47:03 +0000 Subject: [PATCH] Fix ip_allocation module for netaddr-0.7.5 There is a bug that prevents checking whether an IP in string form is in an IPNetwork. Explicitly convert the string to an IPAddress to workaround this. --- ansible/roles/ip-allocation/library/ip_allocation.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ansible/roles/ip-allocation/library/ip_allocation.py b/ansible/roles/ip-allocation/library/ip_allocation.py index b8c2f23a8..73c9dacb0 100644 --- a/ansible/roles/ip-allocation/library/ip_allocation.py +++ b/ansible/roles/ip-allocation/library/ip_allocation.py @@ -133,10 +133,12 @@ def update_allocation(module, allocations): object_name = "%s_ips" % net_name net_allocations = allocations.setdefault(object_name, {}) invalid_allocations = {hn: ip for hn, ip in net_allocations.items() - if ip not in network} + if netaddr.IPAddress(ip) not in network} if invalid_allocations: module.fail_json(msg="Found invalid existing allocations in network %s: %s" % - (network, ", ".join("%s: %s" % (hn, ip) for hn, ip in invalid_allocations.items()))) + (network, + ", ".join("%s: %s" % (hn, ip) + for hn, ip in invalid_allocations.items()))) if hostname not in net_allocations: result['changed'] = True allocated_ips = netaddr.IPSet(net_allocations.values())