From 7e5e9bd7e8ddd09061562f207a5461f8874d9eaa Mon Sep 17 00:00:00 2001 From: Dag Wieers Date: Fri, 10 Jun 2016 19:24:43 +0200 Subject: [PATCH] Validate return code and fail properly (#2334) This fixes #2333 --- .../modules/extras/windows/win_regmerge.ps1 | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/lib/ansible/modules/extras/windows/win_regmerge.ps1 b/lib/ansible/modules/extras/windows/win_regmerge.ps1 index 3bd1547968b..87e73a69773 100644 --- a/lib/ansible/modules/extras/windows/win_regmerge.ps1 +++ b/lib/ansible/modules/extras/windows/win_regmerge.ps1 @@ -69,9 +69,14 @@ If ( $do_comparison -eq $True ) { { # Something is different, actually do reg merge $reg_import_args = @("IMPORT", "$path") - & reg.exe $reg_import_args - Set-Attr $result "changed" $True - Set-Attr $result "difference_count" $comparison_result.count + $ret = & reg.exe $reg_import_args 2>&1 + If ($LASTEXITCODE -eq 0) { + Set-Attr $result "changed" $True + Set-Attr $result "difference_count" $comparison_result.count + } Else { + Set-Attr $result "rc" $LASTEXITCODE + Fail-Json $result "$ret" + } } Else { Set-Attr $result "difference_count" 0 } @@ -82,9 +87,14 @@ If ( $do_comparison -eq $True ) { } Else { # not comparing, merge and report changed $reg_import_args = @("IMPORT", "$path") - & reg.exe $reg_import_args - Set-Attr $result "changed" $True - Set-Attr $result "compared" $False + $ret = & reg.exe $reg_import_args 2>&1 + If ( $LASTEXITCODE -eq 0 ) { + Set-Attr $result "changed" $True + Set-Attr $result "compared" $False + } Else { + Set-Attr $result "rc" $LASTEXITCODE + Fail-Json $result "$ret" + } } Exit-Json $result