mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-19 19:30:22 -07:00
Ensure exit_json returns failed = False
This is required for modules that may return a non-zero `rc` value for a successful run, similar to #24865 for Windows fixing **win_chocolatey**. We also disable the dependency on `rc` value only, even if `failed` was set. Adapted unit and integration tests to the new scheme. Updated raw, shell, script, expect to take `rc` into account.
This commit is contained in:
parent
1f78715848
commit
0e160d5c7e
17 changed files with 68 additions and 56 deletions
|
@ -2023,6 +2023,9 @@ class AnsibleModule(object):
|
|||
assert 'msg' in kwargs, "implementation error -- msg to explain the error is required"
|
||||
kwargs['failed'] = True
|
||||
|
||||
if not 'changed' in kwargs:
|
||||
kwargs['changed'] = False
|
||||
|
||||
self.do_cleanup_files()
|
||||
self._return_formatted(kwargs)
|
||||
sys.exit(1)
|
||||
|
|
|
@ -62,6 +62,10 @@ Function Exit-Json($obj)
|
|||
$obj = @{ }
|
||||
}
|
||||
|
||||
if (-not $obj.ContainsKey('changed')) {
|
||||
Set-Attr $obj "changed" $false
|
||||
}
|
||||
|
||||
echo $obj | ConvertTo-Json -Compress -Depth 99
|
||||
Exit
|
||||
}
|
||||
|
@ -88,6 +92,10 @@ Function Fail-Json($obj, $message = $null)
|
|||
Set-Attr $obj "msg" $message
|
||||
Set-Attr $obj "failed" $true
|
||||
|
||||
if (-not $obj.ContainsKey('changed')) {
|
||||
Set-Attr $obj "changed" $false
|
||||
}
|
||||
|
||||
echo $obj | ConvertTo-Json -Compress -Depth 99
|
||||
Exit 1
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue