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.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* add changelog fragment for group5-batch1

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* 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.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Alexei Znamensky
2026-04-13 07:50:25 +12:00
committed by GitHub
parent 61060532f9
commit b40608a39d
14 changed files with 26 additions and 2 deletions

View File

@@ -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).

View File

@@ -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"

View File

@@ -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):

View File

@@ -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"]

View File

@@ -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"])

View File

@@ -271,6 +271,7 @@ def main():
variant=dict(aliases=["variants"], type="str"),
)
)
module.run_command_environ_update = {"LANGUAGE": "C", "LC_ALL": "C"}
stdout = ""
stderr = ""

View File

@@ -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)

View File

@@ -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"]

View File

@@ -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)

View File

@@ -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)

View File

@@ -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')")

View File

@@ -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()

View File

@@ -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)

View File

@@ -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"})