From 6e0dd0dc595e7ced4889df4e332053ca6d572e73 Mon Sep 17 00:00:00 2001 From: Chris Meyers Date: Thu, 14 May 2015 17:08:49 -0400 Subject: [PATCH] fixed fact cache sender to work when gather_facts: false --- awx/plugins/fact_caching/tower.py | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/awx/plugins/fact_caching/tower.py b/awx/plugins/fact_caching/tower.py index f369d9fa79..5d0516b92b 100755 --- a/awx/plugins/fact_caching/tower.py +++ b/awx/plugins/fact_caching/tower.py @@ -65,20 +65,22 @@ class CacheModule(BaseCacheModule): str(e))) sys.exit(1) - def identify_ansible_facts(self, facts): - ansible_keys = {} - for k in facts.keys(): - if k.startswith('ansible_'): - ansible_keys[k] = 1 - return ansible_keys + def filter_ansible_facts(self, facts): + return dict((k, facts[k]) for k in facts.keys() if k.startswith('ansible_')) def identify_new_module(self, key, value): + # Return the first key found that doesn't exist in the + # previous set of facts if key in self._cache_prev: value_old = self._cache_prev[key] for k,v in value.iteritems(): if k not in value_old: if not k.startswith('ansible_'): return k + # First time we have seen facts from this host + # it's either ansible facts or a module facts (including module_setup) + elif len(value) == 1: + return value.iterkeys().next() return None def get(self, key): @@ -105,13 +107,7 @@ class CacheModule(BaseCacheModule): def set(self, key, value): module = self.identify_new_module(key, value) # Assume ansible fact triggered the set if no new module found - facts = {} - if not module: - keys = self.identify_ansible_facts(value) - for k in keys: - facts[k] = value[k] - else: - facts[module] = value[module] + facts = self.filter_ansible_facts(value) if not module else dict({ module : value[module]}) self._cache_prev = deepcopy(self._cache) self._cache[key] = value