From ea465e21c3641109cb90ffe6f7cd46371dee0796 Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Mon, 6 Apr 2026 10:05:05 +0200 Subject: [PATCH] [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 c90b5046264a24aa6c247e542099915afadd3df8) Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com> Co-authored-by: Claude Sonnet 4.6 --- ...11738-run-command-locale-group3-batch1.yml | 8 ++++++++ plugins/modules/alternatives.py | 2 +- plugins/modules/apk.py | 2 +- plugins/modules/apt_rpm.py | 20 +++++++++++++------ plugins/modules/cargo.py | 2 +- plugins/modules/filesystem.py | 2 +- plugins/modules/git_config.py | 2 +- plugins/modules/git_config_info.py | 2 +- 8 files changed, 28 insertions(+), 12 deletions(-) create mode 100644 changelogs/fragments/11738-run-command-locale-group3-batch1.yml diff --git a/changelogs/fragments/11738-run-command-locale-group3-batch1.yml b/changelogs/fragments/11738-run-command-locale-group3-batch1.yml new file mode 100644 index 0000000000..febf391ab3 --- /dev/null +++ b/changelogs/fragments/11738-run-command-locale-group3-batch1.yml @@ -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). diff --git a/plugins/modules/alternatives.py b/plugins/modules/alternatives.py index c422e88f11..12853ac3d8 100644 --- a/plugins/modules/alternatives.py +++ b/plugins/modules/alternatives.py @@ -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() diff --git a/plugins/modules/apk.py b/plugins/modules/apk.py index b738a77c35..604d6bb862 100644 --- a/plugins/modules/apk.py +++ b/plugins/modules/apk.py @@ -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)] diff --git a/plugins/modules/apt_rpm.py b/plugins/modules/apt_rpm.py index 57c3d21d2c..3e17b9f0a3 100644 --- a/plugins/modules/apt_rpm.py +++ b/plugins/modules/apt_rpm.py @@ -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: diff --git a/plugins/modules/cargo.py b/plugins/modules/cargo.py index 2d7709ce15..e53a391956 100644 --- a/plugins/modules/cargo.py +++ b/plugins/modules/cargo.py @@ -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 diff --git a/plugins/modules/filesystem.py b/plugins/modules/filesystem.py index 93b78613f1..92c6a846be 100644 --- a/plugins/modules/filesystem.py +++ b/plugins/modules/filesystem.py @@ -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 diff --git a/plugins/modules/git_config.py b/plugins/modules/git_config.py index 19c00633ef..385d5b5f25 100644 --- a/plugins/modules/git_config.py +++ b/plugins/modules/git_config.py @@ -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" diff --git a/plugins/modules/git_config_info.py b/plugins/modules/git_config_info.py index 9f3289b203..c648983bea 100644 --- a/plugins/modules/git_config_info.py +++ b/plugins/modules/git_config_info.py @@ -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"]