raiseAnsibleError("error, fact_caching_connection is not set, cannot use fact cache")
raiseAnsibleError("error, 'jsonfile' cache plugin requires the 'fact_caching_connection' config option to be set (to a writeable directory path)")
ifnotos.path.exists(self._cache_dir):
try:
os.makedirs(self._cache_dir)
except(OSError,IOError)ase:
display.warning("error while trying to create cache dir %s : %s"%(self._cache_dir,to_bytes(e)))
display.warning("error in 'jsonfile' cache plugin while trying to create cache dir %s : %s"%(self._cache_dir,to_bytes(e)))
returnNone
defget(self,key):
@ -80,12 +81,12 @@ class CacheModule(BaseCacheModule):
self._cache[key]=value
returnvalue
exceptValueErrorase:
display.warning("error while trying to read %s : %s. Most likely a corrupt file, so erasing and failing."%(cachefile,to_bytes(e)))
display.warning("error in 'jsonfile' cache plugin while trying to read %s : %s. Most likely a corrupt file, so erasing and failing."%(cachefile,to_bytes(e)))
self.delete(key)
raiseAnsibleError("The JSON cache file %s was corrupt, or did not otherwise contain valid JSON data."
" It has been removed, so you can re-run your command now."%cachefile)
except(OSError,IOError)ase:
display.warning("error while trying to read %s : %s"%(cachefile,to_bytes(e)))
display.warning("error in 'jsonfile' cache plugin while trying to read %s : %s"%(cachefile,to_bytes(e)))
raiseKeyError
defset(self,key,value):
@ -96,7 +97,7 @@ class CacheModule(BaseCacheModule):
try:
f=codecs.open(cachefile,'w',encoding='utf-8')
except(OSError,IOError)ase:
display.warning("error while trying to write to %s : %s"%(cachefile,to_bytes(e)))
display.warning("error in 'jsonfile' cache plugin while trying to write to %s : %s"%(cachefile,to_bytes(e)))
pass
else:
f.write(jsonify(value,format=True))
@ -118,7 +119,7 @@ class CacheModule(BaseCacheModule):
ife.errno==errno.ENOENT:
returnFalse
else:
display.warning("error while trying to stat %s : %s"%(cachefile,to_bytes(e)))
display.warning("error in 'jsonfile' cache plugin while trying to stat %s : %s"%(cachefile,to_bytes(e)))
pass
iftime.time()-st.st_mtime<=self._timeout:
@ -150,7 +151,7 @@ class CacheModule(BaseCacheModule):
ife.errno==errno.ENOENT:
returnFalse
else:
display.warning("error while trying to stat %s : %s"%(cachefile,to_bytes(e)))
display.warning("error in 'jsonfile' cache plugin while trying to stat %s : %s"%(cachefile,to_bytes(e)))