diff --git a/lib/ansible/modules/windows/win_command.ps1 b/lib/ansible/modules/windows/win_command.ps1 index 0b8f01bb52a..0c4d36da75b 100644 --- a/lib/ansible/modules/windows/win_command.ps1 +++ b/lib/ansible/modules/windows/win_command.ps1 @@ -159,6 +159,10 @@ $proc.WaitForExit() | Out-Null $result.rc = $proc.ExitCode +If ($result.rc -ne 0) { + $result.failed = $true +} + $end_datetime = [DateTime]::UtcNow $result.start = $start_datetime.ToString("yyyy-MM-dd hh:mm:ss.ffffff") diff --git a/lib/ansible/modules/windows/win_shell.ps1 b/lib/ansible/modules/windows/win_shell.ps1 index af99612c318..3b1e2d163b1 100644 --- a/lib/ansible/modules/windows/win_shell.ps1 +++ b/lib/ansible/modules/windows/win_shell.ps1 @@ -168,6 +168,10 @@ $proc.WaitForExit() | Out-Null $result.rc = $proc.ExitCode +If ($result.rc -ne 0) { + $result.failed = $true +} + $end_datetime = [DateTime]::UtcNow $result.start = $start_datetime.ToString("yyyy-MM-dd hh:mm:ss.ffffff") diff --git a/test/integration/targets/win_command/tasks/main.yml b/test/integration/targets/win_command/tasks/main.yml index 4c5ba95fca7..afd02510f82 100644 --- a/test/integration/targets/win_command/tasks/main.yml +++ b/test/integration/targets/win_command/tasks/main.yml @@ -120,6 +120,7 @@ assert: that: - cmdout|failed + - cmdout.failed == True # check the failure key explicitly, since failed does magic with RC - cmdout.rc == 254 - name: interleave large writes between stdout/stderr (check for buffer consumption deadlock) diff --git a/test/integration/targets/win_shell/tasks/main.yml b/test/integration/targets/win_shell/tasks/main.yml index 7d6ecf52c6e..89d011d8bd7 100644 --- a/test/integration/targets/win_shell/tasks/main.yml +++ b/test/integration/targets/win_shell/tasks/main.yml @@ -47,6 +47,7 @@ assert: that: - shellout|failed + - shellout.failed == true # check the failure key explicitly, since failed does magic with RC - shellout|changed - shellout.cmd == 'bogus_command1234' - shellout.delta is match('^\d:(\d){2}:(\d){2}.(\d){6}$') @@ -147,6 +148,7 @@ assert: that: - shellout|failed + - shellout.failed == True # check the failure key explicitly, since failed does magic with RC - shellout.rc == 254 - name: run something via cmd that will fail in powershell