From c16c4a32d1d4435885129fca0c06cfdd63a95565 Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Fri, 5 Jul 2024 08:54:04 +0200 Subject: [PATCH] [PR #8517/5259caac backport][stable-9] cmd_runner - handle special value "auto" in param force_lang (#8581) cmd_runner - handle special value "auto" in param force_lang (#8517) * cmd_runner - handle special value "auto" in param force_lang * add changelog frag * update doc in puppet * fix markup (cherry picked from commit 5259caacae58204b7140a373a11dcb5ac5f2365e) Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com> --- changelogs/fragments/8517-cmd-runner-lang-auto.yml | 2 ++ plugins/module_utils/cmd_runner.py | 9 ++++++++- plugins/modules/puppet.py | 2 ++ 3 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/8517-cmd-runner-lang-auto.yml diff --git a/changelogs/fragments/8517-cmd-runner-lang-auto.yml b/changelogs/fragments/8517-cmd-runner-lang-auto.yml new file mode 100644 index 0000000000..086a74e997 --- /dev/null +++ b/changelogs/fragments/8517-cmd-runner-lang-auto.yml @@ -0,0 +1,2 @@ +minor_changes: + - CmdRunner module utils - the parameter ``force_lang`` now supports the special value ``auto`` which will automatically try and determine the best parsable locale in the system (https://github.com/ansible-collections/community.general/pull/8517). diff --git a/plugins/module_utils/cmd_runner.py b/plugins/module_utils/cmd_runner.py index da4f1b6fc5..95167a282d 100644 --- a/plugins/module_utils/cmd_runner.py +++ b/plugins/module_utils/cmd_runner.py @@ -11,6 +11,7 @@ from functools import wraps from ansible.module_utils.common.collections import is_sequence from ansible.module_utils.six import iteritems +from ansible.module_utils.common.locale import get_best_parsable_locale def _ensure_list(value): @@ -236,7 +237,13 @@ class CmdRunner(object): fmt = _Format.as_func(func=fmt, ignore_none=True) self.arg_formats[fmt_name] = fmt self.check_rc = check_rc - self.force_lang = force_lang + if force_lang == "auto": + try: + self.force_lang = get_best_parsable_locale() + except RuntimeWarning: + self.force_lang = "C" + else: + self.force_lang = force_lang self.path_prefix = path_prefix if environ_update is None: environ_update = {} diff --git a/plugins/modules/puppet.py b/plugins/modules/puppet.py index 073a083247..46326c667f 100644 --- a/plugins/modules/puppet.py +++ b/plugins/modules/puppet.py @@ -128,6 +128,8 @@ options: - The default value, V(C), is supported on every system, but can lead to encoding errors if UTF-8 is used in the output - Use V(C.UTF-8) or V(en_US.UTF-8) or similar UTF-8 supporting locales in case of problems. You need to make sure the selected locale is supported on the system the puppet agent runs on. + - Starting with community.general 9.1.0, you can use the value V(auto) and the module will + try and determine the best parseable locale to use. type: str default: C version_added: 8.6.0