[PR #11738/c90b5046 backport][stable-12] Ensure standard locale in run_command (group3-batch1) (#11739)

Ensure standard locale in run_command (group3-batch1) (#11738)

* ensure standard locale in run_command (group3-batch1)

* add changelog frag

* fix changelog fragment: bugfixes, not minor_changes



* fix changelog fragment: American English, separate code spans per variable



---------


(cherry picked from commit c90b504626)

Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
patchback[bot]
2026-04-06 10:05:05 +02:00
committed by GitHub
parent f00f70f849
commit ea465e21c3
8 changed files with 28 additions and 12 deletions

View File

@@ -0,0 +1,8 @@
bugfixes:
- alternatives - normalize locale environment for ``run_command()`` calls to ``LANGUAGE=C``, ``LC_ALL=C`` (https://github.com/ansible-collections/community.general/issues/11737, https://github.com/ansible-collections/community.general/pull/11738).
- apk - normalize locale environment for ``run_command()`` calls to ``LANGUAGE=C``, ``LC_ALL=C`` (https://github.com/ansible-collections/community.general/issues/11737, https://github.com/ansible-collections/community.general/pull/11738).
- apt_rpm - normalize locale environment for ``run_command()`` calls to ``LANGUAGE=C``, ``LC_ALL=C`` (https://github.com/ansible-collections/community.general/issues/11737, https://github.com/ansible-collections/community.general/pull/11738).
- cargo - normalize locale environment for ``run_command()`` calls to ``LANGUAGE=C``, ``LC_ALL=C`` (https://github.com/ansible-collections/community.general/issues/11737, https://github.com/ansible-collections/community.general/pull/11738).
- filesystem - normalize locale environment for ``run_command()`` calls to ``LANGUAGE=C``, ``LC_ALL=C`` (https://github.com/ansible-collections/community.general/issues/11737, https://github.com/ansible-collections/community.general/pull/11738).
- git_config - normalize locale environment for ``run_command()`` calls to ``LANGUAGE=C``, ``LC_ALL=C`` (https://github.com/ansible-collections/community.general/issues/11737, https://github.com/ansible-collections/community.general/pull/11738).
- git_config_info - normalize locale environment for ``run_command()`` calls to ``LANGUAGE=C``, ``LC_ALL=C`` (https://github.com/ansible-collections/community.general/issues/11737, https://github.com/ansible-collections/community.general/pull/11738).

View File

@@ -163,7 +163,7 @@ class AlternativesModule:
def __init__(self, module):
self.module = module
self.result = dict(changed=False, diff=dict(before=dict(), after=dict()))
self.module.run_command_environ_update = {"LC_ALL": "C"}
self.module.run_command_environ_update = {"LANGUAGE": "C", "LC_ALL": "C"}
self.messages = []
self.run()

View File

@@ -342,7 +342,7 @@ def main():
)
# Set LANG env since we parse stdout
module.run_command_environ_update = dict(LANG="C", LC_ALL="C", LC_MESSAGES="C", LC_CTYPE="C")
module.run_command_environ_update = dict(LANGUAGE="C", LC_ALL="C")
global APK_PATH
APK_PATH = [module.get_bin_path("apk", required=True)]

View File

@@ -175,7 +175,7 @@ def check_package_version(module, name):
# if newest version already installed return True
# otherwise return False
rc, out, err = module.run_command([APT_CACHE, "policy", name], environ_update={"LANG": "C"})
rc, out, err = module.run_command([APT_CACHE, "policy", name], environ_update={"LANGUAGE": "C", "LC_ALL": "C"})
installed = re.split("\n |: ", out)[2]
candidate = re.split("\n |: ", out)[4]
return installed >= candidate
@@ -204,7 +204,9 @@ def query_package_provides(module, name, allow_upgrade=False):
def update_package_db(module):
rc, update_out, err = module.run_command([APT_PATH, "update"], check_rc=True, environ_update={"LANG": "C"})
rc, update_out, err = module.run_command(
[APT_PATH, "update"], check_rc=True, environ_update={"LANGUAGE": "C", "LC_ALL": "C"}
)
return (False, update_out)
@@ -223,12 +225,16 @@ def clean(module):
def dist_upgrade(module):
rc, out, err = module.run_command([APT_PATH, "-y", "dist-upgrade"], check_rc=True, environ_update={"LANG": "C"})
rc, out, err = module.run_command(
[APT_PATH, "-y", "dist-upgrade"], check_rc=True, environ_update={"LANGUAGE": "C", "LC_ALL": "C"}
)
return (APT_GET_ZERO not in out, out)
def update_kernel(module):
rc, out, err = module.run_command(["/usr/sbin/update-kernel", "-y"], check_rc=True, environ_update={"LANG": "C"})
rc, out, err = module.run_command(
["/usr/sbin/update-kernel", "-y"], check_rc=True, environ_update={"LANGUAGE": "C", "LC_ALL": "C"}
)
return (UPDATE_KERNEL_ZERO not in out, out)
@@ -243,7 +249,9 @@ def remove_packages(module, packages):
if not query_package(module, package):
continue
rc, out, err = module.run_command([APT_PATH, "-y", "remove", package], environ_update={"LANG": "C"})
rc, out, err = module.run_command(
[APT_PATH, "-y", "remove", package], environ_update={"LANGUAGE": "C", "LC_ALL": "C"}
)
if rc != 0:
module.fail_json(msg=f"failed to remove {package}: {err}")
@@ -267,7 +275,7 @@ def install_packages(module, pkgspec, allow_upgrade=False):
if packages:
command = [APT_PATH, "-y", "install"] + packages
rc, out, err = module.run_command(command, environ_update={"LANG": "C"})
rc, out, err = module.run_command(command, environ_update={"LANGUAGE": "C", "LC_ALL": "C"})
installed = True
for package in pkgspec:

View File

@@ -254,7 +254,7 @@ def main():
module.fail_json(msg="Source directory does not exist")
# Set LANG env since we parse stdout
module.run_command_environ_update = dict(LANG="C", LC_ALL="C", LC_MESSAGES="C", LC_CTYPE="C")
module.run_command_environ_update = dict(LANGUAGE="C", LC_ALL="C")
cargo = Cargo(module, **module.params)
changed, out, err = False, None, None

View File

@@ -213,7 +213,7 @@ class Filesystem:
CHANGE_UUID_OPTION: str | None = None
CHANGE_UUID_OPTION_HAS_ARG = True
LANG_ENV = {"LANG": "C", "LC_ALL": "C", "LC_MESSAGES": "C"}
LANG_ENV = {"LANGUAGE": "C", "LC_ALL": "C"}
def __init__(self, module):
self.module = module

View File

@@ -163,7 +163,7 @@ def main():
params = module.params
# We check error message for a pattern, so we need to make sure the messages appear in the form we're expecting.
# Set the locale to C to ensure consistent messages.
module.run_command_environ_update = dict(LANG="C", LC_ALL="C", LC_MESSAGES="C", LC_CTYPE="C")
module.run_command_environ_update = dict(LANGUAGE="C", LC_ALL="C")
name = params["name"] or ""
unset = params["state"] == "absent"

View File

@@ -122,7 +122,7 @@ def main():
# We check error message for a pattern, so we need to make sure the messages appear in the form we're expecting.
# Set the locale to C to ensure consistent messages.
module.run_command_environ_update = dict(LANG="C", LC_ALL="C", LC_MESSAGES="C", LC_CTYPE="C")
module.run_command_environ_update = dict(LANGUAGE="C", LC_ALL="C")
name = module.params["name"]
path = module.params["path"]