mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-06 21:32:49 +00:00
powershell.ps1: Ensure Fail-Json() works with Hashtables (#21697)
Without this change a dictionary $result object would be emptied if it is anything but a PSCustomObject. Now we also support Hashtables.
This commit is contained in:
@@ -19,14 +19,18 @@
|
||||
|
||||
$parsed_args = Parse-Args $args
|
||||
|
||||
$sleep_delay_sec = Get-AnsibleParam $parsed_args "sleep_delay_sec" -default 0
|
||||
$fail_mode = Get-AnsibleParam $parsed_args "fail_mode" -default "success" -validateset "success","graceful","exception"
|
||||
$sleep_delay_sec = Get-AnsibleParam -obj $parsed_args -name "sleep_delay_sec" -type "int" -default 0
|
||||
$fail_mode = Get-AnsibleParam -obj $parsed_args -name "fail_mode" -type "str" -default "success" -validateset "success","graceful","exception"
|
||||
|
||||
If($fail_mode -isnot [array]) {
|
||||
$fail_mode = @($fail_mode)
|
||||
}
|
||||
|
||||
$result = @{changed=$true; module_pid=$pid; module_tempdir=$PSScriptRoot}
|
||||
$result = @{
|
||||
changed = $true
|
||||
module_pid = $pid
|
||||
module_tempdir = $PSScriptRoot
|
||||
}
|
||||
|
||||
If($sleep_delay_sec -gt 0) {
|
||||
Sleep -Seconds $sleep_delay_sec
|
||||
@@ -37,13 +41,13 @@ If($fail_mode -contains "leading_junk") {
|
||||
Write-Output "leading junk before module output"
|
||||
}
|
||||
|
||||
If($fail_mode -contains "graceful") {
|
||||
Fail-Json $result "failed gracefully"
|
||||
}
|
||||
|
||||
Try {
|
||||
|
||||
If($fail_mode -contains "graceful") {
|
||||
Fail-Json $result "failed gracefully"
|
||||
}
|
||||
|
||||
If($fail_mode -eq "exception") {
|
||||
If($fail_mode -contains "exception") {
|
||||
Throw "failing via exception"
|
||||
}
|
||||
|
||||
|
||||
@@ -116,7 +116,7 @@
|
||||
that:
|
||||
- asyncresult.ansible_job_id is match('\d+\.\d+')
|
||||
- asyncresult.finished == 1
|
||||
- asyncresult.changed == false
|
||||
- asyncresult.changed == true
|
||||
- asyncresult | failed == true
|
||||
- asyncresult.msg == 'failed gracefully'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user