diff options
-rw-r--r-- | changelogs/fragments/83498-command-tb-env.yml | 2 | ||||
-rw-r--r-- | lib/ansible/plugins/shell/__init__.py | 6 | ||||
-rw-r--r-- | test/integration/targets/shell/tasks/command-building.yml | 1 |
3 files changed, 8 insertions, 1 deletions
diff --git a/changelogs/fragments/83498-command-tb-env.yml b/changelogs/fragments/83498-command-tb-env.yml new file mode 100644 index 0000000000..b28ad18114 --- /dev/null +++ b/changelogs/fragments/83498-command-tb-env.yml @@ -0,0 +1,2 @@ +bugfixes: + - Fix a traceback when an environment variable contains certain special characters (https://github.com/ansible/ansible/issues/83498) diff --git a/lib/ansible/plugins/shell/__init__.py b/lib/ansible/plugins/shell/__init__.py index dd9f6553ec..f96d9dbdff 100644 --- a/lib/ansible/plugins/shell/__init__.py +++ b/lib/ansible/plugins/shell/__init__.py @@ -211,7 +211,11 @@ class ShellBase(AnsiblePlugin): arg_path, ] - return f'{env_string}%s' % self.join(cps for cp in cmd_parts if cp and (cps := cp.strip())) + cleaned_up_cmd = self.join( + stripped_cmd_part for raw_cmd_part in cmd_parts + if raw_cmd_part and (stripped_cmd_part := raw_cmd_part.strip()) + ) + return ''.join((env_string, cleaned_up_cmd)) def append_command(self, cmd, cmd_to_append): """Append an additional command if supported by the shell""" diff --git a/test/integration/targets/shell/tasks/command-building.yml b/test/integration/targets/shell/tasks/command-building.yml index bd452618b5..d22f67467c 100644 --- a/test/integration/targets/shell/tasks/command-building.yml +++ b/test/integration/targets/shell/tasks/command-building.yml @@ -28,6 +28,7 @@ ANSIBLE_REMOTE_TMP: '{{ atd }}' ANSIBLE_NOCOLOR: "1" ANSIBLE_FORCE_COLOR: "0" + TEST: "foo%D" register: command_building delegate_to: localhost |