config encode errors should not be fatal (#63311)
* fixes #63310 * subset of fixes from #58638 * added warning on error
This commit is contained in:
parent
9d014778ad
commit
77de663879
2
changelogs/fragments/config_encoding_resilience.yml
Normal file
2
changelogs/fragments/config_encoding_resilience.yml
Normal file
|
@ -0,0 +1,2 @@
|
|||
bugfixes:
|
||||
- config - encoding failures on config values should be non-fatal (https://github.com/ansible/ansible/issues/63310)
|
|
@ -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('value for config entry {0} contains invalid characters, ignoring...'.format(to_native(name)))
|
||||
continue
|
||||
if temp_value is not None: # only set if env var is defined
|
||||
value = temp_value
|
||||
origin = name
|
||||
|
|
|
@ -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')
|
||||
|
|
Loading…
Reference in a new issue