diff --git a/changelogs/fragments/shell-wrap_for_exec_deprecation.yml b/changelogs/fragments/shell-wrap_for_exec_deprecation.yml new file mode 100644 index 00000000000..89453c44608 --- /dev/null +++ b/changelogs/fragments/shell-wrap_for_exec_deprecation.yml @@ -0,0 +1,5 @@ +deprecated_features: + - >- + Deprecated the shell plugin's ``wrap_for_exec`` function. This API is not used in Ansible or any known collection + and is being removed to simplify the plugin API. Plugin authors should wrap their command to execute within an + explicit shell or other known executable. diff --git a/lib/ansible/plugins/action/script.py b/lib/ansible/plugins/action/script.py index 0f2b2d49892..2149bef91ca 100644 --- a/lib/ansible/plugins/action/script.py +++ b/lib/ansible/plugins/action/script.py @@ -139,8 +139,6 @@ class ActionModule(ActionBase): else: script_cmd = ' '.join([env_string, target_command]) - script_cmd = self._connection._shell.wrap_for_exec(script_cmd) - exec_data = None # PowerShell runs the script in a special wrapper to enable things # like become and environment args @@ -149,7 +147,7 @@ class ActionModule(ActionBase): pc = self._task exec_data = ps_manifest._create_powershell_wrapper( name=f"ansible.builtin.script.{pathlib.Path(source).stem}", - module_data=to_bytes(script_cmd), + module_data=to_bytes(f"& {script_cmd}; exit $LASTEXITCODE"), module_path=source, module_args={}, environment=env_dict, diff --git a/lib/ansible/plugins/shell/__init__.py b/lib/ansible/plugins/shell/__init__.py index 225ec1f3b06..a633f1d20de 100644 --- a/lib/ansible/plugins/shell/__init__.py +++ b/lib/ansible/plugins/shell/__init__.py @@ -27,6 +27,9 @@ import time from ansible.errors import AnsibleError from ansible.module_utils.common.text.converters import to_native from ansible.plugins import AnsiblePlugin +from ansible.utils.display import Display + +display = Display() _USER_HOME_PATH_RE = re.compile(r'^~[_.A-Za-z0-9][-_.A-Za-z0-9]*$') @@ -269,6 +272,11 @@ class ShellBase(AnsiblePlugin): def wrap_for_exec(self, cmd): """wrap script execution with any necessary decoration (eg '&' for quoted powershell script paths)""" + display.deprecated( + msg='The Shell.wrap_for_exec method is deprecated.', + help_text="Contact plugin author to update their plugin to not use this method.", + version='2.24', + ) return cmd def quote(self, cmd): diff --git a/lib/ansible/plugins/shell/powershell.py b/lib/ansible/plugins/shell/powershell.py index 27a65bdeb91..48d6a8d77cd 100644 --- a/lib/ansible/plugins/shell/powershell.py +++ b/lib/ansible/plugins/shell/powershell.py @@ -428,6 +428,7 @@ class ShellModule(ShellBase): return self._encode_script(script, preserve_rc=False) def wrap_for_exec(self, cmd): + super().wrap_for_exec(cmd) return '& %s; exit $LASTEXITCODE' % cmd def _unquote(self, value):