From a1e6884f969dc1e0d6811f435a35c37b455341f1 Mon Sep 17 00:00:00 2001 From: Jordan Borean Date: Sat, 18 Jul 2020 07:44:21 +1000 Subject: [PATCH] win async - use full path for powershell (#70703) (#70713) (cherry picked from commit 154efd97f218b7f50fef8331251acc0dd7565ae7) --- changelogs/fragments/win_async_full_path.yml | 2 ++ lib/ansible/executor/powershell/async_wrapper.ps1 | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/win_async_full_path.yml diff --git a/changelogs/fragments/win_async_full_path.yml b/changelogs/fragments/win_async_full_path.yml new file mode 100644 index 00000000000..b9b9087ced7 --- /dev/null +++ b/changelogs/fragments/win_async_full_path.yml @@ -0,0 +1,2 @@ +bugfixes: +- windows async - use full path when calling PowerShell to reduce reliance on environment vars being correct - https://github.com/ansible/ansible/issues/70655 diff --git a/lib/ansible/executor/powershell/async_wrapper.ps1 b/lib/ansible/executor/powershell/async_wrapper.ps1 index 545b4a5623c..1947dcb5739 100644 --- a/lib/ansible/executor/powershell/async_wrapper.ps1 +++ b/lib/ansible/executor/powershell/async_wrapper.ps1 @@ -87,7 +87,8 @@ $bootstrap_wrapper = { $bootstrap_wrapper = $bootstrap_wrapper.ToString().Replace('$pipe_name = ""', "`$pipe_name = `"$pipe_name`"") $bootstrap_wrapper = $bootstrap_wrapper.Replace('$bytes_length = 0', "`$bytes_length = $($payload_bytes.Count)") $encoded_command = [System.Convert]::ToBase64String([System.Text.Encoding]::Unicode.GetBytes($bootstrap_wrapper)) -$exec_args = "powershell.exe -NonInteractive -NoProfile -ExecutionPolicy Bypass -EncodedCommand $encoded_command" +$pwsh_path = "$env:SystemRoot\System32\WindowsPowerShell\v1.0\powershell.exe" +$exec_args = "`"$pwsh_path`" -NonInteractive -NoProfile -ExecutionPolicy Bypass -EncodedCommand $encoded_command" # create a named pipe that is set to allow only the current user read access $current_user = ([Security.Principal.WindowsIdentity]::GetCurrent()).User