Hi all,
There’s been some chatter about getting some sort of functionality for running tasks as scheduled jobs into the builtin powershell functions in Ansible.
I’ve spent a few hours today on a rought draft, and would really like some feedback.
The version I’m working on can be found in my fork here: https://github.com/trondhindenes/ansible/blob/async_test/lib/ansible/module_utils/powershell.ps1
(The whole fork is being kept up to date from ansible:devel, so just cloning the fork and running hacking/env-setup is probably the easist way to test it)
As for writing modules which support scheduled tasks, here’s an example:
https://gist.github.com/trondhindenes/d679a6a427d74d72dfd7
In short, everything inside the “$IsScheduledJob -eq $true” block will execute as a scheduled job, along with everything before.
Anything inside the “else” block will run during the “regular” execution which Ansible does, which will happen after the scheduled job has completed. This means that this block is responsible for parsing the result of
the scheduled job, and returning that down to Ansible. I’ve created a helper function for that ($job in my example), which outputs an object containing result (success/failure) and the output object from the scheduled task (generated from exit-json/fail-json during scheduled task execution).
From what I can see it’s looking good, so I’d really like to get some feedback on this!
-Trond