clear insights system id if not found

* Host previously found to have an insights system id that then later
are found to not have an insights system id, have their system id
cleared.
This commit is contained in:
Chris Meyers
2017-05-12 12:00:30 -04:00
parent 3cdc332497
commit eb27233e5c
2 changed files with 11 additions and 17 deletions

View File

@@ -123,15 +123,12 @@ class FactBrokerWorker(ConsumerMixin):
if job.store_facts is True: if job.store_facts is True:
if module_name == 'insights': if module_name == 'insights':
system_id = facts.get('system_id', None) system_id = facts.get('system_id', None)
if system_id:
host_obj.insights_system_id = system_id host_obj.insights_system_id = system_id
try: try:
host_obj.save() host_obj.save()
except IntegrityError: except IntegrityError:
host_obj.insights_system_id = None host_obj.insights_system_id = None
logger.warn('Inisghts system_id %s not assigned to host %s because it already exists.' % (system_id, host_obj.pk)) logger.warn('Inisghts system_id %s not assigned to host %s because it already exists.' % (system_id, host_obj.pk))
else:
logger.warn('Failed to find insights system id in insights fact scan.')
self._do_gather_facts_update(host_obj, module_name, facts, self.timestamp) self._do_gather_facts_update(host_obj, module_name, facts, self.timestamp)
message.ack() message.ack()

View File

@@ -52,7 +52,6 @@ def main():
system_uuid = get_system_uuid(INSIGHTS_SYSTEM_ID_FILE) system_uuid = get_system_uuid(INSIGHTS_SYSTEM_ID_FILE)
if system_uuid is not None:
results = { results = {
'ansible_facts': { 'ansible_facts': {
'insights': { 'insights': {
@@ -60,8 +59,6 @@ def main():
} }
} }
} }
else:
results = dict(skipped=True, msg="Insights system id not found")
module.exit_json(**results) module.exit_json(**results)