From 6652464e257ded724a12a0abcbc8c410d1f0dd5d Mon Sep 17 00:00:00 2001 From: Seth Foster Date: Tue, 28 Apr 2020 10:52:15 -0400 Subject: [PATCH] Unset old instance IP when conflicting new instance IP With AWX_AUTO_DEPROVISION_INSTANCES on, instances are registered with an ip address. However, new instances might try to register before old instances are deprivisioned. In this case old IPs can conflict with the new ones. This will check for an ip conflict and unset the IP of conflicting instance (set to None) ansible/awx issue 6750 --- awx/main/managers.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/awx/main/managers.py b/awx/main/managers.py index 9f1537fd6f..2076e7f0b0 100644 --- a/awx/main/managers.py +++ b/awx/main/managers.py @@ -121,6 +121,17 @@ class InstanceManager(models.Manager): if not hostname: hostname = settings.CLUSTER_HOST_ID with advisory_lock('instance_registration_%s' % hostname): + if settings.AWX_AUTO_DEPROVISION_INSTANCES: + # detect any instances with the same IP address. + # if one exists, set it to None + inst_conflicting_ip = self.filter(ip_address=ip_address).exclude(hostname=hostname) + if inst_conflicting_ip.exists(): + for other_inst in inst_conflicting_ip: + other_hostname = other_inst.hostname + other_inst.ip_address = None + other_inst.save(update_fields=['ip_address']) + logger.warning("IP address {0} conflict detected, ip address unset for host {1}.".format(ip_address, other_hostname)) + instance = self.filter(hostname=hostname) if instance.exists(): instance = instance.get()