1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

win_become: move error handling to Ansible outside of shell (#31227)

* win_become: move error handling to Ansible outside of shell

* trimmed the output so double newlines don't get set

* added test for non-zero exit code

* missed issue URL on test

* changed exit to SetShouldExit
This commit is contained in:
Jordan Borean 2017-10-04 12:42:27 +11:00 committed by ansibot
parent 34878926ca
commit e61c2799ff
2 changed files with 7 additions and 10 deletions

View file

@ -801,15 +801,8 @@ Function Run($payload) {
# FUTURE: decode CLIXML stderr output (and other streams?) # FUTURE: decode CLIXML stderr output (and other streams?)
$rc = [Ansible.Shell.NativeProcessUtil]::GetProcessExitCode($pi.hProcess) $rc = [Ansible.Shell.NativeProcessUtil]::GetProcessExitCode($pi.hProcess)
[Console]::Out.WriteLine($str_stdout.Trim())
If ($rc -eq 0) { [Console]::Error.WriteLine($str_stderr.Trim())
$str_stdout
$str_stderr
}
Else {
Throw "failed, rc was $rc, stderr was $str_stderr, stdout was $str_stdout"
}
} }
Catch { Catch {
$excep = $_ $excep = $_
@ -818,7 +811,7 @@ Function Run($payload) {
Finally { Finally {
Remove-Item $temp -ErrorAction SilentlyContinue Remove-Item $temp -ErrorAction SilentlyContinue
} }
$host.SetShouldExit($rc)
} }
''' # end become_wrapper ''' # end become_wrapper

View file

@ -71,6 +71,10 @@
that: that:
- whoami_out.stdout_lines[0].endswith(become_test_username) - 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: 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 # FUTURE: add standalone playbook tests to include password prompting and play become keywords