From f576082949e1eab5d4fcdc46ee15b7fd31c82d75 Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Tue, 10 May 2016 15:54:46 -0400 Subject: [PATCH] restore old jsonfile behaviour on key expiration fixes #14456, now it won't expire keys in middle of a play when they were 'valid' at 'gather time'. --- lib/ansible/plugins/cache/jsonfile.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/ansible/plugins/cache/jsonfile.py b/lib/ansible/plugins/cache/jsonfile.py index f0ec635ebe..a99f5a3e31 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: