summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorToshio Kuratomi <toshio@fedoraproject.org>2016-02-07 13:20:26 -0800
committerToshio Kuratomi <toshio@fedoraproject.org>2016-02-07 14:26:49 -0800
commit8d6a3b166c87f1182a60f3c1a2f775d05a9666d9 (patch)
tree77ce9b767c8c3a8baa2c5517df186c7ae07592b2
parenta2bdab720d52bb0dc6f9fafe952d8925847aadf0 (diff)
downloadansible-modules-core-8d6a3b166c87f1182a60f3c1a2f775d05a9666d9.tar.gz
use new method of setting locale and other environment variables
The old method left settings in the environment. The new method takes care of clearing them after use. In this module, the old method was also setting the environment too late to affect all the command line tools which lead to a bug. Fixes https://github.com/ansible/ansible/issues/14264
-rwxr-xr-xpackaging/os/apt.py25
1 files changed, 10 insertions, 15 deletions
diff --git a/packaging/os/apt.py b/packaging/os/apt.py
index f764bbcf..8e4be1a6 100755
--- a/packaging/os/apt.py
+++ b/packaging/os/apt.py
@@ -173,9 +173,14 @@ import itertools
# APT related constants
APT_ENV_VARS = dict(
- DEBIAN_FRONTEND = 'noninteractive',
- DEBIAN_PRIORITY = 'critical',
- LANG = 'C'
+ DEBIAN_FRONTEND = 'noninteractive',
+ DEBIAN_PRIORITY = 'critical',
+ # We screenscrape apt-get and aptitude output for information so we need
+ # to make sure we use the C locale when running commands
+ LANG = 'C',
+ LC_ALL = 'C',
+ LC_MESSAGES = 'C',
+ LC_CTYPE = 'C',
)
DPKG_OPTIONS = 'force-confdef,force-confold'
@@ -375,9 +380,6 @@ def install(m, pkgspec, cache, upgrade=False, default_release=None,
else:
check_arg = ''
- for (k,v) in APT_ENV_VARS.iteritems():
- os.environ[k] = v
-
if build_dep:
cmd = "%s -y %s %s %s build-dep %s" % (APT_GET_CMD, dpkg_options, force_yes, check_arg, packages)
else:
@@ -442,9 +444,6 @@ def install_deb(m, debs, cache, force, install_recommends, dpkg_options):
if force:
options += " --force-all"
- for (k,v) in APT_ENV_VARS.iteritems():
- os.environ[k] = v
-
cmd = "dpkg %s -i %s" % (options, " ".join(pkgs_to_install))
rc, out, err = m.run_command(cmd)
if "stdout" in retvals:
@@ -482,9 +481,6 @@ def remove(m, pkgspec, cache, purge=False,
else:
purge = ''
- for (k,v) in APT_ENV_VARS.iteritems():
- os.environ[k] = v
-
cmd = "%s -q -y %s %s remove %s" % (APT_GET_CMD, dpkg_options, purge, packages)
if m.check_mode:
@@ -528,9 +524,6 @@ def upgrade(m, mode="yes", force=False, default_release=None,
apt_cmd_path = m.get_bin_path(apt_cmd, required=True)
- for (k,v) in APT_ENV_VARS.iteritems():
- os.environ[k] = v
-
cmd = '%s -y %s %s %s %s' % (apt_cmd_path, dpkg_options,
force_yes, check_arg, upgrade_command)
@@ -564,6 +557,8 @@ def main():
supports_check_mode = True
)
+ module.run_command_environ_update = APT_ENV_VARS
+
if not HAS_PYTHON_APT:
try:
module.run_command('apt-get update && apt-get install python-apt -y -q --force-yes', use_unsafe_shell=True, check_rc=True)