2016-09-07 00:38:12 +00:00
|
|
|
#!powershell
|
|
|
|
# This file is part of Ansible
|
|
|
|
#
|
|
|
|
# Ansible is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# Ansible is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
# WANT_JSON
|
|
|
|
# POWERSHELL_COMMON
|
|
|
|
|
|
|
|
$parsed_args = Parse-Args $args
|
|
|
|
|
2017-02-24 07:08:19 +00: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 00:38:12 +00:00
|
|
|
|
|
|
|
If($fail_mode -isnot [array]) {
|
|
|
|
$fail_mode = @($fail_mode)
|
|
|
|
}
|
|
|
|
|
2017-02-24 07:08:19 +00:00
|
|
|
$result = @{
|
|
|
|
changed = $true
|
|
|
|
module_pid = $pid
|
|
|
|
module_tempdir = $PSScriptRoot
|
|
|
|
}
|
2016-09-07 00:38:12 +00: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 07:08:19 +00:00
|
|
|
If($fail_mode -contains "graceful") {
|
|
|
|
Fail-Json $result "failed gracefully"
|
|
|
|
}
|
2016-09-07 00:38:12 +00:00
|
|
|
|
2017-02-24 07:08:19 +00:00
|
|
|
Try {
|
2016-09-07 00:38:12 +00:00
|
|
|
|
2017-02-24 07:08:19 +00:00
|
|
|
If($fail_mode -contains "exception") {
|
2016-09-07 00:38:12 +00:00
|
|
|
Throw "failing via exception"
|
|
|
|
}
|
|
|
|
|
|
|
|
Exit-Json $result
|
|
|
|
}
|
|
|
|
Finally
|
|
|
|
{
|
|
|
|
If($fail_mode -contains "trailing_junk") {
|
|
|
|
Write-Output "trailing junk after module output"
|
|
|
|
}
|
|
|
|
}
|