From 18d9c34e9d7276cd803c5ace67d51fd0e51049f9 Mon Sep 17 00:00:00 2001 From: Dag Wieers Date: Thu, 20 Jul 2017 23:34:48 +0200 Subject: [PATCH] win_command, win_shell: Use Fail-Json on failure (#26512) Two reasons to do this: - It provides a proper error message indicating why it failed - It conforms to what is being done in the command and shell modules --- lib/ansible/modules/windows/win_command.ps1 | 8 ++++---- lib/ansible/modules/windows/win_msg.ps1 | 2 +- lib/ansible/modules/windows/win_shell.ps1 | 8 ++++---- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/ansible/modules/windows/win_command.ps1 b/lib/ansible/modules/windows/win_command.ps1 index 0c4d36da75b..f2763d0295b 100644 --- a/lib/ansible/modules/windows/win_command.ps1 +++ b/lib/ansible/modules/windows/win_command.ps1 @@ -159,14 +159,14 @@ $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") $result.end = $end_datetime.ToString("yyyy-MM-dd hh:mm:ss.ffffff") $result.delta = $($end_datetime - $start_datetime).ToString("h\:mm\:ss\.ffffff") +If ($result.rc -ne 0) { + Fail-Json -obj $result -message "non-zero return code" +} + Exit-Json $result diff --git a/lib/ansible/modules/windows/win_msg.ps1 b/lib/ansible/modules/windows/win_msg.ps1 index 92ce049f0ea..04cf80b2ba4 100644 --- a/lib/ansible/modules/windows/win_msg.ps1 +++ b/lib/ansible/modules/windows/win_msg.ps1 @@ -56,7 +56,7 @@ $result.runtime_seconds = $stopwatch.Elapsed.TotalSeconds $result.sent_localtime = $endsend_at.Trim() if ($result.rc -ne 0 ) { - Fail-Json $result "$output" + Fail-Json -obj $result -message "$output" } Exit-Json $result diff --git a/lib/ansible/modules/windows/win_shell.ps1 b/lib/ansible/modules/windows/win_shell.ps1 index 3b1e2d163b1..3e4f4dc4414 100644 --- a/lib/ansible/modules/windows/win_shell.ps1 +++ b/lib/ansible/modules/windows/win_shell.ps1 @@ -168,14 +168,14 @@ $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") $result.end = $end_datetime.ToString("yyyy-MM-dd hh:mm:ss.ffffff") $result.delta = $($end_datetime - $start_datetime).ToString("h\:mm\:ss\.ffffff") +If ($result.rc -ne 0) { + Fail-Json -obj $result -message "non-zero return code" +} + Exit-Json $result