From d01187d03b1ffd0d792fc1a205c442c3cdbfd3a5 Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Sun, 12 Apr 2026 22:29:14 +0200 Subject: [PATCH] [PR #11768/b40608a3 backport][stable-12] Ensure standard locale in run_command (group5-batch1) (#11795) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ensure standard locale in run_command (group5-batch1) (#11768) * ensure standard locale in run_command (group5-batch1) Adds ``LANGUAGE=C`` and ``LC_ALL=C`` to ``run_command()`` calls in modules that parse command output, to prevent locale-dependent parsing failures on non-C-locale systems. Modules updated: apache2_module, composer, facter_facts, known_hosts module utils, lvg_rename, macports, modprobe, monit, open_iscsi, pacman_key, rhsm_release, rpm_ostree_pkg, sysupgrade. * add changelog fragment for group5-batch1 * Remove lvg_rename from locale fix — superseded by PR #11746 PR #11746 (feat: use CmdRunner for LVM commands) takes priority and will handle lvg_rename.py via CmdRunner refactor. Removing our run_command_environ_update change to avoid conflict. --------- (cherry picked from commit b40608a39d5c195059096523cbebd1053aedc841) Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com> Co-authored-by: Claude Sonnet 4.6 --- changelogs/fragments/11768-group5-batch1-locale.yml | 13 +++++++++++++ plugins/module_utils/known_hosts.py | 2 +- plugins/modules/apache2_module.py | 1 + plugins/modules/composer.py | 1 + plugins/modules/facter_facts.py | 1 + plugins/modules/macports.py | 1 + plugins/modules/modprobe.py | 1 + plugins/modules/monit.py | 1 + plugins/modules/open_iscsi.py | 1 + plugins/modules/pacman_key.py | 1 + plugins/modules/rhsm_release.py | 1 + plugins/modules/rpm_ostree_pkg.py | 1 + plugins/modules/sysupgrade.py | 1 + tests/unit/plugins/module_utils/test_known_hosts.py | 2 +- 14 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/11768-group5-batch1-locale.yml diff --git a/changelogs/fragments/11768-group5-batch1-locale.yml b/changelogs/fragments/11768-group5-batch1-locale.yml new file mode 100644 index 0000000000..07a4e953cf --- /dev/null +++ b/changelogs/fragments/11768-group5-batch1-locale.yml @@ -0,0 +1,13 @@ +bugfixes: + - apache2_module - ensure ``LANGUAGE=C`` and ``LC_ALL=C`` are set when running commands that parse output (https://github.com/ansible-collections/community.general/issues/11737, https://github.com/ansible-collections/community.general/pull/11768). + - composer - ensure ``LANGUAGE=C`` and ``LC_ALL=C`` are set when running commands that parse output (https://github.com/ansible-collections/community.general/issues/11737, https://github.com/ansible-collections/community.general/pull/11768). + - facter_facts - ensure ``LANGUAGE=C`` and ``LC_ALL=C`` are set when running commands that parse output (https://github.com/ansible-collections/community.general/issues/11737, https://github.com/ansible-collections/community.general/pull/11768). + - known_hosts module utils - ensure ``LANGUAGE=C`` and ``LC_ALL=C`` are set when running commands that parse output (https://github.com/ansible-collections/community.general/issues/11737, https://github.com/ansible-collections/community.general/pull/11768). + - macports - ensure ``LANGUAGE=C`` and ``LC_ALL=C`` are set when running commands that parse output (https://github.com/ansible-collections/community.general/issues/11737, https://github.com/ansible-collections/community.general/pull/11768). + - modprobe - ensure ``LANGUAGE=C`` and ``LC_ALL=C`` are set when running commands that parse output (https://github.com/ansible-collections/community.general/issues/11737, https://github.com/ansible-collections/community.general/pull/11768). + - monit - ensure ``LANGUAGE=C`` and ``LC_ALL=C`` are set when running commands that parse output (https://github.com/ansible-collections/community.general/issues/11737, https://github.com/ansible-collections/community.general/pull/11768). + - open_iscsi - ensure ``LANGUAGE=C`` and ``LC_ALL=C`` are set when running commands that parse output (https://github.com/ansible-collections/community.general/issues/11737, https://github.com/ansible-collections/community.general/pull/11768). + - pacman_key - ensure ``LANGUAGE=C`` and ``LC_ALL=C`` are set when running commands that parse output (https://github.com/ansible-collections/community.general/issues/11737, https://github.com/ansible-collections/community.general/pull/11768). + - rhsm_release - ensure ``LANGUAGE=C`` and ``LC_ALL=C`` are set when running commands that parse output (https://github.com/ansible-collections/community.general/issues/11737, https://github.com/ansible-collections/community.general/pull/11768). + - rpm_ostree_pkg - ensure ``LANGUAGE=C`` and ``LC_ALL=C`` are set when running commands that parse output (https://github.com/ansible-collections/community.general/issues/11737, https://github.com/ansible-collections/community.general/pull/11768). + - sysupgrade - ensure ``LANGUAGE=C`` and ``LC_ALL=C`` are set when running commands that parse output (https://github.com/ansible-collections/community.general/issues/11737, https://github.com/ansible-collections/community.general/pull/11768). diff --git a/plugins/module_utils/known_hosts.py b/plugins/module_utils/known_hosts.py index 2e27f8585c..76942d3655 100644 --- a/plugins/module_utils/known_hosts.py +++ b/plugins/module_utils/known_hosts.py @@ -152,7 +152,7 @@ def add_host_key(module, fqdn, port=22, key_type="rsa", create_dir=False): else: this_cmd = f"{keyscan_cmd} -t {key_type} {fqdn}" - rc, out, err = module.run_command(this_cmd) + rc, out, err = module.run_command(this_cmd, environ_update={"LANGUAGE": "C", "LC_ALL": "C"}) # ssh-keyscan gives a 0 exit code and prints nothing on timeout if rc != 0 or not out: msg = "failed to retrieve hostkey" diff --git a/plugins/modules/apache2_module.py b/plugins/modules/apache2_module.py index da00f94abe..3538463e7f 100644 --- a/plugins/modules/apache2_module.py +++ b/plugins/modules/apache2_module.py @@ -245,6 +245,7 @@ def main(): ), supports_check_mode=True, ) + module.run_command_environ_update = {"LANGUAGE": "C", "LC_ALL": "C"} name = module.params["name"] if name == "cgi" and module.params["state"] == "present" and _run_threaded(module): diff --git a/plugins/modules/composer.py b/plugins/modules/composer.py index 731cfa1250..c7d5cfe67f 100644 --- a/plugins/modules/composer.py +++ b/plugins/modules/composer.py @@ -227,6 +227,7 @@ def main(): required_if=[("global_command", False, ["working_dir"])], supports_check_mode=True, ) + module.run_command_environ_update = {"LANGUAGE": "C", "LC_ALL": "C"} # Get composer command with fallback to default command = module.params["command"] diff --git a/plugins/modules/facter_facts.py b/plugins/modules/facter_facts.py index d38805ca81..a91d53ba2b 100644 --- a/plugins/modules/facter_facts.py +++ b/plugins/modules/facter_facts.py @@ -69,6 +69,7 @@ def main(): ), supports_check_mode=True, ) + module.run_command_environ_update = {"LANGUAGE": "C", "LC_ALL": "C"} facter_path = module.get_bin_path("facter", opt_dirs=["/opt/puppetlabs/bin"]) diff --git a/plugins/modules/macports.py b/plugins/modules/macports.py index 906bfcbcb3..815aacf1d9 100644 --- a/plugins/modules/macports.py +++ b/plugins/modules/macports.py @@ -271,6 +271,7 @@ def main(): variant=dict(aliases=["variants"], type="str"), ) ) + module.run_command_environ_update = {"LANGUAGE": "C", "LC_ALL": "C"} stdout = "" stderr = "" diff --git a/plugins/modules/modprobe.py b/plugins/modules/modprobe.py index 27501353b3..b438ee4b51 100644 --- a/plugins/modules/modprobe.py +++ b/plugins/modules/modprobe.py @@ -298,6 +298,7 @@ def build_module(): def main(): module = build_module() + module.run_command_environ_update = {"LANGUAGE": "C", "LC_ALL": "C"} modprobe = Modprobe(module) diff --git a/plugins/modules/monit.py b/plugins/modules/monit.py index f2eb01abd2..a458029e46 100644 --- a/plugins/modules/monit.py +++ b/plugins/modules/monit.py @@ -322,6 +322,7 @@ def main(): ) module = AnsibleModule(argument_spec=arg_spec, supports_check_mode=True) + module.run_command_environ_update = {"LANGUAGE": "C", "LC_ALL": "C"} name = module.params["name"] state = module.params["state"] diff --git a/plugins/modules/open_iscsi.py b/plugins/modules/open_iscsi.py index 2b3fe9f636..304be79559 100644 --- a/plugins/modules/open_iscsi.py +++ b/plugins/modules/open_iscsi.py @@ -390,6 +390,7 @@ def main(): ], supports_check_mode=True, ) + module.run_command_environ_update = {"LANGUAGE": "C", "LC_ALL": "C"} global iscsiadm_cmd iscsiadm_cmd = module.get_bin_path("iscsiadm", required=True) diff --git a/plugins/modules/pacman_key.py b/plugins/modules/pacman_key.py index 344714c7ce..dd562009ad 100644 --- a/plugins/modules/pacman_key.py +++ b/plugins/modules/pacman_key.py @@ -361,6 +361,7 @@ def main(): mutually_exclusive=(("data", "file", "url", "keyserver"),), required_if=[("state", "present", ("data", "file", "url", "keyserver"), True)], ) + module.run_command_environ_update = {"LANGUAGE": "C", "LC_ALL": "C"} PacmanKey(module) diff --git a/plugins/modules/rhsm_release.py b/plugins/modules/rhsm_release.py index f0218c9c07..03d5e90c85 100644 --- a/plugins/modules/rhsm_release.py +++ b/plugins/modules/rhsm_release.py @@ -107,6 +107,7 @@ def main(): ), supports_check_mode=True, ) + module.run_command_environ_update = {"LANGUAGE": "C", "LC_ALL": "C"} if os.getuid() != 0: module.fail_json(msg="Interacting with subscription-manager requires root permissions ('become: true')") diff --git a/plugins/modules/rpm_ostree_pkg.py b/plugins/modules/rpm_ostree_pkg.py index b9a1aab765..64401ce726 100644 --- a/plugins/modules/rpm_ostree_pkg.py +++ b/plugins/modules/rpm_ostree_pkg.py @@ -190,6 +190,7 @@ def main(): ), ), ) + module.run_command_environ_update = {"LANGUAGE": "C", "LC_ALL": "C"} rpm_ostree_pkg = RpmOstreePkg(module) rpm_ostree_pkg.ensure() diff --git a/plugins/modules/sysupgrade.py b/plugins/modules/sysupgrade.py index 44fe93f09c..99f6a0692b 100644 --- a/plugins/modules/sysupgrade.py +++ b/plugins/modules/sysupgrade.py @@ -133,6 +133,7 @@ def main(): ), supports_check_mode=False, ) + module.run_command_environ_update = {"LANGUAGE": "C", "LC_ALL": "C"} return_dict = sysupgrade_run(module) module.exit_json(**return_dict) diff --git a/tests/unit/plugins/module_utils/test_known_hosts.py b/tests/unit/plugins/module_utils/test_known_hosts.py index 38cda65c95..66e47e8adf 100644 --- a/tests/unit/plugins/module_utils/test_known_hosts.py +++ b/tests/unit/plugins/module_utils/test_known_hosts.py @@ -117,4 +117,4 @@ def test_add_host_key(mocker, fqdn, port, add_host_key_cmd): mocker.patch("os.path.exists", return_value=True) known_hosts.add_host_key(am, fqdn, port=port) - run_command.assert_called_with(keyscan_cmd + add_host_key_cmd) + run_command.assert_called_with(keyscan_cmd + add_host_key_cmd, environ_update={"LANGUAGE": "C", "LC_ALL": "C"})