From 1df8ebf0c32676d531eb5809a66a941c27ad73e3 Mon Sep 17 00:00:00 2001 From: Toshio Kuratomi Date: Sun, 7 Feb 2016 13:20:26 -0800 Subject: [PATCH] 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 --- packaging/os/apt.py | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/packaging/os/apt.py b/packaging/os/apt.py index cafe57eaf15..9b8389ea011 100755 --- a/packaging/os/apt.py +++ b/packaging/os/apt.py @@ -181,9 +181,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' @@ -388,9 +393,6 @@ def install(m, pkgspec, cache, upgrade=False, default_release=None, else: autoremove = '' - 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: @@ -455,9 +457,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: @@ -495,9 +494,6 @@ def remove(m, pkgspec, cache, purge=False, else: purge = '' - for (k,v) in APT_ENV_VARS.iteritems(): - os.environ[k] = v - if autoremove: autoremove = '--auto-remove' else: @@ -546,9 +542,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) @@ -583,6 +576,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)