diff --git a/lib/ansible/plugins/cache/jsonfile.py b/lib/ansible/plugins/cache/jsonfile.py index 848e905de3..bf60fcf7f7 100644 --- a/lib/ansible/plugins/cache/jsonfile.py +++ b/lib/ansible/plugins/cache/jsonfile.py @@ -29,6 +29,8 @@ from ansible import constants as C from ansible.errors import * from ansible.parsing.utils.jsonify import jsonify from ansible.plugins.cache.base import BaseCacheModule +from ansible.utils.unicode import to_bytes + class CacheModule(BaseCacheModule): """ @@ -46,7 +48,7 @@ class CacheModule(BaseCacheModule): try: os.makedirs(self._cache_dir) except (OSError,IOError) as e: - self._display.warning("error while trying to create cache dir %s : %s" % (self._cache_dir, str(e))) + self._display.warning("error while trying to create cache dir %s : %s" % (self._cache_dir, to_bytes(e))) return None def get(self, key): @@ -61,7 +63,7 @@ class CacheModule(BaseCacheModule): try: f = codecs.open(cachefile, 'r', encoding='utf-8') except (OSError,IOError) as e: - self._display.warning("error while trying to read %s : %s" % (cachefile, str(e))) + self._display.warning("error while trying to read %s : %s" % (cachefile, to_bytes(e))) pass else: try: @@ -69,7 +71,7 @@ class CacheModule(BaseCacheModule): self._cache[key] = value return value except ValueError as e: - self._display.warning("error while trying to read %s : %s. Most likely a corrupt file, so erasing and failing." % (cachefile, str(e))) + self._display.warning("error while trying to read %s : %s. Most likely a corrupt file, so erasing and failing." % (cachefile, to_bytes(e))) self.delete(key) raise AnsibleError("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) finally: @@ -83,7 +85,7 @@ class CacheModule(BaseCacheModule): try: f = codecs.open(cachefile, 'w', encoding='utf-8') except (OSError,IOError) as e: - self._display.warning("error while trying to write to %s : %s" % (cachefile, str(e))) + self._display.warning("error while trying to write to %s : %s" % (cachefile, to_bytes(e))) pass else: f.write(jsonify(value)) @@ -99,7 +101,7 @@ class CacheModule(BaseCacheModule): if e.errno == errno.ENOENT: return False else: - self._display.warning("error while trying to stat %s : %s" % (cachefile, str(e))) + self._display.warning("error while trying to stat %s : %s" % (cachefile, to_bytes(e))) pass if time.time() - st.st_mtime <= self._timeout: @@ -131,7 +133,7 @@ class CacheModule(BaseCacheModule): if e.errno == errno.ENOENT: return False else: - self._display.warning("error while trying to stat %s : %s" % (cachefile, str(e))) + self._display.warning("error while trying to stat %s : %s" % (cachefile, to_bytes(e))) pass def delete(self, key):