diff options
author | Matt Davis <nitzmahone@users.noreply.github.com> | 2019-10-10 13:55:29 -0700 |
---|---|---|
committer | Toshio Kuratomi <a.badger@gmail.com> | 2019-10-10 13:55:29 -0700 |
commit | 1ca6667a2f37e66cf6350be9df8d50959e2dc75a (patch) | |
tree | 11c73f159fb8711fdb143785729311eab4e5224e | |
parent | ae3a79fa588b8434f5f81b204dbe3f0960d70002 (diff) | |
download | ansible-1ca6667a2f37e66cf6350be9df8d50959e2dc75a.tar.gz |
[2.9 backport] config encode errors should not be fatal (#63311) (#63312)
* config encode errors should not be fatal (#63311)
* fixes #63310
* subset of fixes from #58638
* added warning on error
(cherry picked from commit 77de663879bcf2f6ab82d5009b8a0b799814750b)
* bring back text-ification from #63349
-rw-r--r-- | changelogs/fragments/config_encoding_resilience.yml | 2 | ||||
-rw-r--r-- | lib/ansible/config/manager.py | 6 | ||||
-rw-r--r-- | lib/ansible/utils/py3compat.py | 11 |
3 files changed, 15 insertions, 4 deletions
diff --git a/changelogs/fragments/config_encoding_resilience.yml b/changelogs/fragments/config_encoding_resilience.yml new file mode 100644 index 0000000000..eb6905070b --- /dev/null +++ b/changelogs/fragments/config_encoding_resilience.yml @@ -0,0 +1,2 @@ +bugfixes: + - config - encoding failures on config values should be non-fatal (https://github.com/ansible/ansible/issues/63310) diff --git a/lib/ansible/config/manager.py b/lib/ansible/config/manager.py index f76c8bf6ac..de146062e3 100644 --- a/lib/ansible/config/manager.py +++ b/lib/ansible/config/manager.py @@ -390,7 +390,11 @@ class ConfigManager(object): origin = None for entry in entry_list: name = entry.get('name') - temp_value = container.get(name, None) + try: + temp_value = container.get(name, None) + except UnicodeEncodeError: + self.WARNINGS.add(u'value for config entry {0} contains invalid characters, ignoring...'.format(to_text(name))) + continue if temp_value is not None: # only set if env var is defined value = temp_value origin = name diff --git a/lib/ansible/utils/py3compat.py b/lib/ansible/utils/py3compat.py index 5ffb09e9d7..6b46b5e899 100644 --- a/lib/ansible/utils/py3compat.py +++ b/lib/ansible/utils/py3compat.py @@ -27,14 +27,19 @@ class _TextEnviron(MutableMapping): Mimics the behaviour of os.environ on Python3 """ - def __init__(self, env=None): + def __init__(self, env=None, encoding=None): if env is None: env = os.environ self._raw_environ = env self._value_cache = {} # Since we're trying to mimic Python3's os.environ, use sys.getfilesystemencoding() # instead of utf-8 - self.encoding = sys.getfilesystemencoding() + if encoding is None: + # Since we're trying to mimic Python3's os.environ, use sys.getfilesystemencoding() + # instead of utf-8 + self.encoding = sys.getfilesystemencoding() + else: + self.encoding = encoding def __delitem__(self, key): del self._raw_environ[key] @@ -61,4 +66,4 @@ class _TextEnviron(MutableMapping): return len(self._raw_environ) -environ = _TextEnviron() +environ = _TextEnviron(encoding='utf-8') |