diff --git a/lib/ansible/plugins/cache/jsonfile.py b/lib/ansible/plugins/cache/jsonfile.py index f0ec635ebe7..a99f5a3e318 100644 --- a/lib/ansible/plugins/cache/jsonfile.py +++ b/lib/ansible/plugins/cache/jsonfile.py @@ -62,13 +62,16 @@ class CacheModule(BaseCacheModule): return None def get(self, key): - - if self.has_expired(key) or key == "": - raise KeyError + """ This checks the in memory cache first as the fact was not expired at 'gather time' + and it would be problematic if the key did expire after some long running tasks and + user gets 'undefined' error in the same play """ if key in self._cache: return self._cache.get(key) + if self.has_expired(key) or key == "": + raise KeyError + cachefile = "%s/%s" % (self._cache_dir, key) try: with codecs.open(cachefile, 'r', encoding='utf-8') as f: