mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-08 06:12:51 +00:00
Modify the way we set the localization environment
Previously, we set the LANG (and LC_CTYPE) environment variables
directly in the module code and applied them with os.environ().
Instead, we are now pre-pending those variables to the environment
string used to execute the command which allows the user to
override the localization values by setting the environment values
directly (even on a per-task basis):
- subversion: repo=file:///path/to/repos/svn_über dest=/tmp/svntest
environment:
LANG: "C"
LC_CTYPE: "en_US.UTF-8"
So if a user wishes to default their LANG back to C, they can still
avoid unicode issues by doing the above.
Fixes #7060
This commit is contained in:
@@ -287,15 +287,21 @@ class Runner(object):
|
||||
def _compute_environment_string(self, inject=None):
|
||||
''' what environment variables to use when running the command? '''
|
||||
|
||||
if not self.environment:
|
||||
return ""
|
||||
enviro = template.template(self.basedir, self.environment, inject, convert_bare=True)
|
||||
enviro = utils.safe_eval(enviro)
|
||||
if type(enviro) != dict:
|
||||
raise errors.AnsibleError("environment must be a dictionary, received %s" % enviro)
|
||||
default_environment = collections.OrderedDict([
|
||||
('LANG', C.DEFAULT_MODULE_LANG),
|
||||
('LC_CTYPE', C.DEFAULT_MODULE_LANG),
|
||||
])
|
||||
|
||||
if self.environment:
|
||||
enviro = template.template(self.basedir, self.environment, inject, convert_bare=True)
|
||||
enviro = utils.safe_eval(enviro)
|
||||
if type(enviro) != dict:
|
||||
raise errors.AnsibleError("environment must be a dictionary, received %s" % enviro)
|
||||
default_environment.update(enviro)
|
||||
|
||||
result = ""
|
||||
for (k,v) in enviro.iteritems():
|
||||
result = "%s=%s %s" % (k, pipes.quote(unicode(v)), result)
|
||||
for (k,v) in default_environment.iteritems():
|
||||
result = "%s %s=%s" % (result, k, pipes.quote(unicode(v)))
|
||||
return result
|
||||
|
||||
# *****************************************************
|
||||
|
||||
Reference in New Issue
Block a user