2016-09-07 02:38:12 +02:00
|
|
|
#!powershell
|
2018-08-06 01:21:53 +02:00
|
|
|
|
|
|
|
# Copyright: (c) 2018, Ansible Project
|
|
|
|
|
|
|
|
#Requires -Module Ansible.ModuleUtils.Legacy
|
2016-09-07 02:38:12 +02:00
|
|
|
|
|
|
|
$parsed_args = Parse-Args $args
|
|
|
|
|
2017-02-24 08:08:19 +01:00
|
|
|
$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"
|
2016-09-07 02:38:12 +02:00
|
|
|
|
|
|
|
If($fail_mode -isnot [array]) {
|
|
|
|
$fail_mode = @($fail_mode)
|
|
|
|
}
|
|
|
|
|
2017-02-24 08:08:19 +01:00
|
|
|
$result = @{
|
|
|
|
changed = $true
|
|
|
|
module_pid = $pid
|
|
|
|
module_tempdir = $PSScriptRoot
|
|
|
|
}
|
2016-09-07 02:38:12 +02:00
|
|
|
|
|
|
|
If($sleep_delay_sec -gt 0) {
|
|
|
|
Sleep -Seconds $sleep_delay_sec
|
|
|
|
$result["slept_sec"] = $sleep_delay_sec
|
|
|
|
}
|
|
|
|
|
|
|
|
If($fail_mode -contains "leading_junk") {
|
|
|
|
Write-Output "leading junk before module output"
|
|
|
|
}
|
|
|
|
|
2017-02-24 08:08:19 +01:00
|
|
|
If($fail_mode -contains "graceful") {
|
|
|
|
Fail-Json $result "failed gracefully"
|
|
|
|
}
|
2016-09-07 02:38:12 +02:00
|
|
|
|
2017-02-24 08:08:19 +01:00
|
|
|
Try {
|
2016-09-07 02:38:12 +02:00
|
|
|
|
2017-02-24 08:08:19 +01:00
|
|
|
If($fail_mode -contains "exception") {
|
2016-09-07 02:38:12 +02:00
|
|
|
Throw "failing via exception"
|
|
|
|
}
|
|
|
|
|
|
|
|
Exit-Json $result
|
|
|
|
}
|
|
|
|
Finally
|
|
|
|
{
|
|
|
|
If($fail_mode -contains "trailing_junk") {
|
|
|
|
Write-Output "trailing junk after module output"
|
|
|
|
}
|
|
|
|
}
|