diff --git a/lib/ansible/plugins/shell/powershell.py b/lib/ansible/plugins/shell/powershell.py index 18569738817..2787e9f61e5 100644 --- a/lib/ansible/plugins/shell/powershell.py +++ b/lib/ansible/plugins/shell/powershell.py @@ -801,15 +801,8 @@ Function Run($payload) { # FUTURE: decode CLIXML stderr output (and other streams?) $rc = [Ansible.Shell.NativeProcessUtil]::GetProcessExitCode($pi.hProcess) - - If ($rc -eq 0) { - $str_stdout - $str_stderr - } - Else { - Throw "failed, rc was $rc, stderr was $str_stderr, stdout was $str_stdout" - } - + [Console]::Out.WriteLine($str_stdout.Trim()) + [Console]::Error.WriteLine($str_stderr.Trim()) } Catch { $excep = $_ @@ -818,7 +811,7 @@ Function Run($payload) { Finally { Remove-Item $temp -ErrorAction SilentlyContinue } - + $host.SetShouldExit($rc) } ''' # end become_wrapper diff --git a/test/integration/targets/win_become/tasks/main.yml b/test/integration/targets/win_become/tasks/main.yml index 24f2eb0fbe7..ef6c7371455 100644 --- a/test/integration/targets/win_become/tasks/main.yml +++ b/test/integration/targets/win_become/tasks/main.yml @@ -70,6 +70,10 @@ assert: that: - whoami_out.stdout_lines[0].endswith(become_test_username) + + - name: test with module that will return non-zero exit code (https://github.com/ansible/ansible/issues/30468) + vars: *become_vars + setup: # FUTURE: test raw + script become behavior once they're running under the exec wrapper again # FUTURE: add standalone playbook tests to include password prompting and play become keywords