Created
October 4, 2015 13:11
-
-
Save trondhindenes/d679a6a427d74d72dfd7 to your computer and use it in GitHub Desktop.
Example module which uses scheduled jobs to invoke
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!powershell | |
# This file is part of Ansible. | |
# | |
# Copyright 2015, Trond Hindenes <trond@hindenes.com> | |
# | |
# 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 | |
RunAsScheduledJob | |
if ($IsScheduledJob -eq $true) | |
{ | |
$params = Parse-Args $args; | |
$result = New-Object psobject @{ | |
changed = $false | |
} | |
$ShouldFail = Get-AnsibleParam -obj $params -name "should_fail"| ConvertTo-Bool | |
$Message = Get-AnsibleParam -obj $params -name "message" | |
set-attr -obj $result -name "message" -value $message | |
if ($ShouldFail -eq $false) | |
{ | |
exit-json -obj $result | |
} | |
if ($ShouldFail -eq $true) | |
{ | |
fail-json -obj $result | |
} | |
} | |
Else | |
{ | |
$job = GetScheduledJobResult | |
if ($job.result -eq "Success") | |
{ | |
exit-json -obj $job.obj | |
} | |
Else | |
{ | |
fail-json -obj $job.obj | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment