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 module_name == 'insights':
system_id = facts.get('system_id', None)
if system_id:
host_obj.insights_system_id = system_id
try:
host_obj.save()
except IntegrityError:
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))
else:
logger.warn('Failed to find insights system id in insights fact scan.')
host_obj.insights_system_id = system_id
try:
host_obj.save()
except IntegrityError:
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))
self._do_gather_facts_update(host_obj, module_name, facts, self.timestamp)
message.ack()

View File

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