mirror of
https://github.com/ansible/awx.git
synced 2026-05-23 16:47:45 -02:30
add auto-discovered nodes to default IG
* add advisory_lock to avoid IG update race logic * update IG by way of policy_instance_list
This commit is contained in:
@@ -429,6 +429,7 @@ def execution_node_health_check(node):
|
||||
|
||||
|
||||
def inspect_execution_nodes(instance_list):
|
||||
with advisory_lock('inspect_execution_nodes_lock', wait=True):
|
||||
node_lookup = {}
|
||||
for inst in instance_list:
|
||||
if inst.node_type == 'execution':
|
||||
@@ -448,6 +449,16 @@ def inspect_execution_nodes(instance_list):
|
||||
else:
|
||||
defaults = dict(enabled=False)
|
||||
(changed, instance) = Instance.objects.register(hostname=hostname, node_type='execution', defaults=defaults)
|
||||
logger.warn("Registered execution node '{}' (marked as disabled by default)".format(hostname))
|
||||
|
||||
default_ig = InstanceGroup.objects.get(name='default')
|
||||
if instance.hostname not in default_ig.policy_instance_list:
|
||||
default_ig.policy_instance_list += [instance.hostname]
|
||||
default_ig.save()
|
||||
logger.warn("Updated `default` instance group's policy_instance_list to include execution node '{}'".format(hostname))
|
||||
else:
|
||||
logger.warn("`default` instance group's policy_instance_list already listed execution node '{}'".format(hostname))
|
||||
|
||||
was_lost = instance.is_lost(ref_time=nowtime)
|
||||
last_seen = parse_date(ad['Time'])
|
||||
|
||||
@@ -457,7 +468,6 @@ def inspect_execution_nodes(instance_list):
|
||||
instance.save(update_fields=['last_seen'])
|
||||
|
||||
if changed:
|
||||
logger.warn("Registered execution node '{}'".format(hostname))
|
||||
execution_node_health_check.apply_async([hostname])
|
||||
elif was_lost:
|
||||
# if the instance *was* lost, but has appeared again,
|
||||
|
||||
Reference in New Issue
Block a user