1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

win_scheduled_task_stat: add new module to get stat on scheduled tasks (#30602)

* win_scheduled_task_stat: add new module to get stat on scheduled tasks

* fixed up linting errors and aliases file

* I should learn how to spell

* removing URI from test

* added state information for the task

* removed argument so task stays running
This commit is contained in:
Jordan Borean 2017-09-22 05:59:06 +10:00 committed by GitHub
parent 0e9ae5b8cc
commit 59187358ee
11 changed files with 808 additions and 238 deletions

View file

@ -21,6 +21,13 @@ Ansible Changes By Release
ansible_diff_mode, ansible_inventory_sources, ansible_limit, ansible_run_tags , ansible_forks and ansible_skip_tags
* Updated the bundled copy of the six library to 1.11.0
### New Modules
#### Windows
* win_scheduled_task_stat
<a id="2.4"></a>
## 2.4 "Dancing Days" - RELEASE CANDIDATE

View file

@ -547,7 +547,7 @@ Function Compare-Triggers($task_definition) {
$map = @{
[TASK_TRIGGER_TYPE2]::TASK_TRIGGER_BOOT = @{
mandatory = @()
optional = @('enabled', 'end_boundary', 'execution_time_limit', 'start_boundary')
optional = @('delay', 'enabled', 'end_boundary', 'execution_time_limit', 'start_boundary')
}
[TASK_TRIGGER_TYPE2]::TASK_TRIGGER_DAILY = @{
mandatory = @('start_boundary')

View file

@ -127,8 +127,8 @@ options:
description:
- The time to delay the task from running once the trigger has been
fired.
- Optional when C(type) is C(event), C(logon), C(registration),
C(session_state_change).
- Optional when C(type) is C(boot), C(event), C(logon),
C(registration), C(session_state_change).
- Is in the ISO 8601 Duration format C(P[n]Y[n]M[n]DT[n]H[n]M[n]S).
random_delay:
description:
@ -331,7 +331,7 @@ options:
task after it expires.
- A task expires after the end_boundary has been exceeded for all triggers
associated with the task.
- This is in ISO 8601 DateTime format C(YYYY-MM-DDThh:mm:ss).
- This is in the ISO 8601 Duration format C(P[n]Y[n]M[n]DT[n]H[n]M[n]S).
version_added: '2.5'
disallow_start_if_on_batteries:
description:
@ -348,14 +348,14 @@ options:
description:
- The amount of time allowed to complete the task.
- When not set, the time limit is infinite.
- This is in ISO 8601 DateTime format C(YYYY-MM-DDThh:mm:ss).
- This is in the ISO 8601 Duration format C(P[n]Y[n]M[n]DT[n]H[n]M[n]S).
version_added: '2.5'
hidden:
description:
- Whether the task will be hidden in the UI.
type: bool
version_added: '2.5'
mutliple_instances:
multiple_instances:
description:
- An integer that indicates the behaviour when starting a task that is
already running.
@ -367,7 +367,7 @@ options:
- C(3) will stop other instances of the task and start the new one.
choices: [ 0, 1, 2, 3 ]
version_added: '2.5'
priortiy:
priority:
description:
- The priority level (0-10) of the task.
- When creating a new task the default if C(7).
@ -385,7 +385,7 @@ options:
- If this is set then C(restart_count) must also be set.
- The maximum allowed time is 31 days.
- The minimum allowed time is 1 minute.
- This is in ISO 8601 DateTime format C(YYYY-MM-DDThh:mm:ss).
- This is in the ISO 8601 Duration format C(P[n]Y[n]M[n]DT[n]H[n]M[n]S).
version_added: '2.5'
run_only_if_idle:
description:

View file

@ -1,9 +1,14 @@
#!powershell
# Copyright (c) 2017 Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
#Requires -Module Ansible.ModuleUtils.CamelConversion
#Requires -Module Ansible.ModuleUtils.Legacy
#Requires -Module Ansible.ModuleUtils.SID
$params = Parse-Args -arguments $args
$path = Get-AnsibleParam -obj $params -name "path" -type "str" -failifempty $true
$path = Get-AnsibleParam -obj $params -name "path" -type "str" -default "\"
$name = Get-AnsibleParam -obj $params -name "name" -type "str"
$result = @{
@ -37,6 +42,15 @@ public enum TASK_RUN_LEVEL
TASK_RUNLEVEL_HIGHEST = 1
}
public enum TASK_STATE
{
TASK_STATE_UNKNOWN = 0,
TASK_STATE_DISABLED = 1,
TASK_STATE_QUEUED = 2,
TASK_STATE_READY = 3,
TASK_STATE_RUNNING = 4
}
public enum TASK_TRIGGER_TYPE2
{
TASK_TRIGGER_EVENT = 0,
@ -58,6 +72,14 @@ Function Get-PropertyValue($task_property, $com, $property) {
if ($raw_value -eq $null) {
return $null
} elseif ($raw_value.GetType().Name -eq "__ComObject") {
$com_values = @{}
$properties = Get-Member -InputObject $raw_value -MemberType Property | % {
$com_value = Get-PropertyValue -task_property $property -com $raw_value -property $_.Name
$com_values.$property = $com_value
}
return ,$com_values
}
switch ($property) {
@ -212,7 +234,11 @@ Function Get-PropertyValue($task_property, $com, $property) {
}
$service = New-Object -ComObject Schedule.Service
$service.Connect()
try {
$service.Connect()
} catch {
Fail-Json -obj $result -message "failed to connect to the task scheduler service: $($_.Exception.Message)"
}
try {
$task_folder = $service.GetFolder($path)
@ -240,24 +266,36 @@ $result.folder_task_count = $folder_task_count
if ($name -ne $null) {
if ($task -ne $null) {
$task_definition = $task.Definition
$result.task_exists = $true
$result.task = @{}
# task state
$result.state = @{
last_run_time = (Get-Date $task.LastRunTime -Format s)
last_task_result = $task.LastTaskResult
next_run_time = (Get-Date $task.NextRunTime -Format s)
number_of_missed_runs = $task.NumberOfMissedRuns
status = [Enum]::ToObject([TASK_STATE], $task.State).ToString()
}
# task definition
$task_definition = $task.Definition
$ignored_properties = @("XmlText")
$properties = @("principal", "registration_info", "settings")
$collection_properties = @("actions", "triggers")
foreach ($property in $properties) {
$property_name = $property -replace "_"
$result.task.$property = @{}
$result.$property = @{}
$values = $task_definition.$property_name
Get-Member -InputObject $values -MemberType Property | % {
$result.task.$property.$($_.Name) = (Get-PropertyValue -task_property $property -com $values -property $_.Name)
if ($_.Name -notin $ignored_properties) {
$result.$property.$($_.Name) = (Get-PropertyValue -task_property $property -com $values -property $_.Name)
}
}
}
foreach ($property in $collection_properties) {
$result.task.$property = @()
$result.$property = @()
$collection = $task_definition.$property
$collection_count = $collection.Count
for ($i = 1; $i -le $collection_count; $i++) {
@ -265,9 +303,11 @@ if ($name -ne $null) {
$item_info = @{}
Get-Member -InputObject $item -MemberType Property | % {
if ($_.Name -notin $ignored_properties) {
$item_info.$($_.Name) = (Get-PropertyValue -task_property $property -com $item -property $_.Name)
}
$result.task.$property += $item_info
}
$result.$property += $item_info
}
}
} else {
@ -275,4 +315,6 @@ if ($name -ne $null) {
}
}
$result = Convert-DictToSnakeCase -dict $result
Exit-Json -obj $result

View file

@ -0,0 +1,367 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Copyright (c) 2017 Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# this is a windows documentation stub. actual code lives in the .ps1
# file of the same name
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['preview'],
'supported_by': 'community'}
DOCUMENTATION = r'''
---
module: win_scheduled_task_stat
version_added: "2.5"
short_description: Returns information about a Windows Scheduled Task
description:
- Will return whether the folder and task exists.
- Returns the names of tasks in the folder specified.
- If C(name) is set and exists, will return information on the task itself.
- Use M(win_scheduled_task) to configure a scheduled task.
options:
path:
description: The folder path where the task lives.
default: \
name:
description: The name of the scheduled task to get information for.
author:
- Jordan Borean (@jborean93)
'''
EXAMPLES = r'''
- name: get information about a folder
win_scheduled_task_stat:
path: \folder name
register: task_folder_stat
- name: get information about a task in the root folder
win_scheduled_task_stat:
name: task name
register: task_stat
- name: get information about a task in a custom folder
win_scheduled_task_stat:
path: \folder name
name: task name
register: task_stat
'''
RETURN = r'''
actions:
description: A list of actions.
returned: name is specified and task exists
type: list
sample: [
{
"Arguments": "/c echo hi",
"Id": null,
"Path": "cmd.exe",
"Type": "TASK_ACTION_EXEC",
"WorkingDirectory": null
}
]
folder_exists:
description: Whether the folder set at path exists.
returned: always
type: boolean
sample: True
folder_task_count:
description: The number of tasks that exist in the folder.
returned: always
type: int
sample: 2
folder_task_names:
description: A list of tasks that exist in the folder.
returned: always
type: list
sample: [ 'Task 1', 'Task 2' ]
principal:
description: Details on the principal configured to run the task.
returned: name is specified and task exists
type: complex
contains:
display_name:
description: The name of the user/group that is displayed in the Task
Scheduler UI.
returned: ''
type: str
sample: Administrator
group_id:
description: The group that will run the task.
returned: ''
type: str
sample: BUILTIN\Administrators
id:
description: The ID for the principal.
returned: ''
type: str
sample: Author
logon_type:
description: The logon method that the task will run with.
returned: ''
type: str
sample: TASK_LOGON_INTERACTIVE_TOKEN
run_level:
description: The level of user rights used to run the task.
returned: ''
type: str
sample: TASK_RUNLEVEL_LUA
user_id:
description: The user that will run the task.
returned: ''
type: str
sample: SERVER\Administrator
registration_info:
description: Details on the task registration info.
returned: name is specified and task exists
type: complex
contains:
author:
description: The author os the task.
returned: ''
type: str
sample: SERVER\Administrator
date:
description: The date when the task was register.
returned: ''
type: str
sample: '2017-01-01T10:00:00'
description:
description: The description of the task.
returned: ''
type: str
sample: task description
documentation:
description: The documentation of the task.
returned: ''
type: str
sample: task documentation
security_descriptor:
description: The security descriptor of the task.
returned: ''
type: str
sample: security descriptor
source:
description: The source of the task.
returned: ''
type: str
sample: source
uri:
description: The URI/path of the task.
returned: ''
type: str
sample: \task\task name
version:
description: The version of the task.
returned: ''
type: str
sample: 1.0
settings:
description: Details on the task settings.
returned: name is specified and task exists
type: complex
contains:
allow_demand_start:
description: Whether the task can be started by using either the Run
command of the Context menu.
returned: ''
type: bool
sample: True
allow_hard_terminate:
description: Whether the task can terminated by using TerminateProcess.
returned: ''
type: bool
sample: True
compatibility:
description: The compatibility level of the task
returned: ''
type: int
sample: 2
delete_expired_task_after:
description: The amount of time the Task Scheduler will wait before
deleting the task after it expires.
returned: ''
type: str
sample: PT10M
disallow_start_if_on_batteries:
description: Whether the task will not be started if the computer is
running on battery power.
returned: ''
type: bool
sample: False
disallow_start_on_remote_app_session:
description: Whether the task will not be started when in a remote app
session.
returned: ''
type: bool
sample: True
enabled:
description: Whether the task is enabled.
returned: ''
type: bool
sample: True
execution_time_limit:
description: The amount of time allowed to complete the task.
returned: ''
type: str
sample: PT72H
hidden:
description: Whether the task is hidden in the UI.
returned: ''
type: bool
sample: False
idle_settings:
description: The idle settings of the task.
returned: ''
type: dictionary
sample: {
"idle_settings": "PT1H"
}
maintenance_settings:
description: The maintenance settings of the task.
returned: ''
type: str
sample: null
mulitple_instances:
description: Indicates the behaviour when starting a task that is already
running.
returned: ''
type: int
sample: 2
network_settings:
description: The network settings of the task.
returned: ''
type: dictionary
sample: {
"network_settings": null
}
priority:
description: The priority level of the task.
returned: ''
type: int
sample: 7
restart_count:
description: The number of times that the task will attempt to restart
on failures.
returned: ''
type: int
sample: 0
restart_interval:
description: How long the Task Scheduler will attempt to restart the
task.
returned: ''
type: str
sample: PT15M
run_only_id_idle:
description: Whether the task will run if the computer is in an idle
state.
returned: ''
type: bool
sample: True
run_only_if_network_available:
description: Whether the task will run only when a network is available.
returned: ''
type: bool
sample: False
start_when_available:
description: Whether the task can start at any time after its scheduled
time has passed.
returned: ''
type: bool
sample: False
stop_if_going_on_batteries:
description: Whether the task will be stopped if the computer begins to
run on battery power.
returned: ''
type: bool
sample: True
use_unified_scheduling_engine:
description: Whether the task will use the unifed scheduling engine.
returned: ''
type: bool
sample: False
volatile:
description: Whether thet ask is volatile.
returned: ''
type: bool
sample: False
wake_to_run:
description: Whether the task will wake the computer when it is time to
run the task.
returned: ''
type: bool
sample: False
state:
description: Details on the state of the task
returned: name is specified and task exists
type: complex
contains:
last_run_time:
description: The time the registered task was last run.
returned: ''
type: str
sample: '2017-09-20T20:50:00'
last_task_result:
description: The results that were returned the last time the task was
run.
returned: ''
type: int
sample: 267009
next_run_time:
description: The time when the task is next scheduled to run.
returned: ''
type: str
sample: '2017-09-20T22:50:00'
number_of_missed_runs:
description: The number of times a task has missed a scheduled run.
returned: ''
type: int
sample: 1
status:
description: The status of the task, whether it is running, stopped, etc.
returned: ''
type: str
sample: TASK_STATE_RUNNING
task_exists:
description: Whether the task at the folder exists.
returned: name is specified
type: boolean
sample: True
triggers:
description: A list of triggers.
returned: name is specified and task exists
type: list
sample: [
{
"delay": "PT15M",
"enabled": true,
"end_boundary": null,
"execution_time_limit": null,
"id": null,
"repetition": {
"repetition": false
},
"start_boundary": null,
"type": "TASK_TRIGGER_BOOT"
},
{
"days_of_month": "5,15,30",
"enabled": true,
"end_boundary": null,
"execution_time_limit": null,
"id": null,
"months_of_year": "june,december",
"random_delay": null,
"repetition": {
"repetition": false
},
"run_on_last_day_of_month": true,
"start_boundary": "2017-09-20T03:44:38",
"type": "TASK_TRIGGER_MONTHLY"
}
]
'''

View file

@ -11,7 +11,7 @@
check_mode: yes
- name: get result of create task (check mode)
test_task_stat:
win_scheduled_task_stat:
path: \
name: '{{test_scheduled_task_name}}'
register: create_task_result_check
@ -33,7 +33,7 @@
register: create_task
- name: get result of create task
test_task_stat:
win_scheduled_task_stat:
path: \
name: '{{test_scheduled_task_name}}'
register: create_task_result
@ -43,12 +43,12 @@
that:
- create_task|changed
- create_task_result.task_exists == True
- create_task_result.task.actions|count == 1
- create_task_result.task.actions[0].Path == "cmd.exe"
- create_task_result.task.actions[0].Arguments == "/c echo hi"
- create_task_result.task.actions[0].WorkingDirectory == None
- create_task_result.task.registration_info.Description == "Original Description"
- create_task_result.task.triggers|count == 0
- create_task_result.actions|count == 1
- create_task_result.actions[0].path == "cmd.exe"
- create_task_result.actions[0].arguments == "/c echo hi"
- create_task_result.actions[0].working_directory == None
- create_task_result.registration_info.description == "Original Description"
- create_task_result.triggers|count == 0
- name: create task (idempotent)
win_scheduled_task:
@ -78,7 +78,7 @@
check_mode: yes
- name: get result of change task (check mode)
test_task_stat:
win_scheduled_task_stat:
path: \
name: '{{test_scheduled_task_name}}'
register: change_task_result_check
@ -87,12 +87,12 @@
assert:
that:
- change_task_check|changed
- change_task_result_check.task.actions|count == 1
- change_task_result_check.task.registration_info.Author == None
- change_task_result_check.task.registration_info.Description == "Original Description"
- change_task_result_check.task.settings.AllowDemandStart == true
- change_task_result_check.task.settings.RestartCount == 0
- change_task_result_check.task.settings.RestartInterval == None
- change_task_result_check.actions|count == 1
- change_task_result_check.registration_info.author == None
- change_task_result_check.registration_info.description == "Original Description"
- change_task_result_check.settings.allow_demand_start == true
- change_task_result_check.settings.restart_count == 0
- change_task_result_check.settings.restart_interval == None
- name: change task
win_scheduled_task:
@ -106,7 +106,7 @@
register: change_task
- name: get result of change task
test_task_stat:
win_scheduled_task_stat:
path: \
name: '{{test_scheduled_task_name}}'
register: change_task_result
@ -115,12 +115,12 @@
assert:
that:
- change_task|changed
- change_task_result.task.actions|count == 1
- change_task_result.task.registration_info.Author == "Cow Inc."
- change_task_result.task.registration_info.Description == "Test for Ansible"
- change_task_result.task.settings.AllowDemandStart == false
- change_task_result.task.settings.RestartCount == 5
- change_task_result.task.settings.RestartInterval == "PT1M"
- change_task_result.actions|count == 1
- change_task_result.registration_info.author == "Cow Inc."
- change_task_result.registration_info.description == "Test for Ansible"
- change_task_result.settings.allow_demand_start == false
- change_task_result.settings.restart_count == 5
- change_task_result.settings.restart_interval == "PT1M"
- name: change task (idempotent)
win_scheduled_task:
@ -152,7 +152,7 @@
check_mode: yes
- name: get result of add task action (check mode)
test_task_stat:
win_scheduled_task_stat:
path: \
name: '{{test_scheduled_task_name}}'
register: add_task_action_result_check
@ -161,10 +161,10 @@
assert:
that:
- add_task_action_check|changed
- add_task_action_result_check.task.actions|count == 1
- add_task_action_result_check.task.actions[0].Path == "cmd.exe"
- add_task_action_result_check.task.actions[0].Arguments == "/c echo hi"
- add_task_action_result_check.task.actions[0].WorkingDirectory == None
- add_task_action_result_check.actions|count == 1
- add_task_action_result_check.actions[0].path == "cmd.exe"
- add_task_action_result_check.actions[0].arguments == "/c echo hi"
- add_task_action_result_check.actions[0].working_directory == None
- name: add task action
win_scheduled_task:
@ -179,7 +179,7 @@
register: add_task_action
- name: get result of add task action
test_task_stat:
win_scheduled_task_stat:
path: \
name: '{{test_scheduled_task_name}}'
register: add_task_action_result
@ -188,13 +188,13 @@
assert:
that:
- add_task_action|changed
- add_task_action_result.task.actions|count == 2
- add_task_action_result.task.actions[0].Path == "cmd.exe"
- add_task_action_result.task.actions[0].Arguments == "/c echo hi"
- add_task_action_result.task.actions[0].WorkingDirectory == None
- add_task_action_result.task.actions[1].Path == "powershell.exe"
- add_task_action_result.task.actions[1].Arguments == "-File C:\\ansible\\script.ps1"
- add_task_action_result.task.actions[1].WorkingDirectory == "C:\\ansible"
- add_task_action_result.actions|count == 2
- add_task_action_result.actions[0].path == "cmd.exe"
- add_task_action_result.actions[0].arguments == "/c echo hi"
- add_task_action_result.actions[0].working_directory == None
- add_task_action_result.actions[1].path == "powershell.exe"
- add_task_action_result.actions[1].arguments == "-File C:\\ansible\\script.ps1"
- add_task_action_result.actions[1].working_directory == "C:\\ansible"
- name: add task action (idempotent)
win_scheduled_task:
@ -225,7 +225,7 @@
check_mode: yes
- name: get result of remove task action (check mode)
test_task_stat:
win_scheduled_task_stat:
path: \
name: '{{test_scheduled_task_name}}'
register: remove_task_action_result_check
@ -234,13 +234,13 @@
assert:
that:
- remove_task_action_check|changed
- remove_task_action_result_check.task.actions|count == 2
- remove_task_action_result_check.task.actions[0].Path == "cmd.exe"
- remove_task_action_result_check.task.actions[0].Arguments == "/c echo hi"
- remove_task_action_result_check.task.actions[0].WorkingDirectory == None
- remove_task_action_result_check.task.actions[1].Path == "powershell.exe"
- remove_task_action_result_check.task.actions[1].Arguments == "-File C:\\ansible\\script.ps1"
- remove_task_action_result_check.task.actions[1].WorkingDirectory == "C:\\ansible"
- remove_task_action_result_check.actions|count == 2
- remove_task_action_result_check.actions[0].path == "cmd.exe"
- remove_task_action_result_check.actions[0].arguments == "/c echo hi"
- remove_task_action_result_check.actions[0].working_directory == None
- remove_task_action_result_check.actions[1].path == "powershell.exe"
- remove_task_action_result_check.actions[1].arguments == "-File C:\\ansible\\script.ps1"
- remove_task_action_result_check.actions[1].working_directory == "C:\\ansible"
- name: remove task action
win_scheduled_task:
@ -253,7 +253,7 @@
register: remove_task_action
- name: get result of remove task action
test_task_stat:
win_scheduled_task_stat:
path: \
name: '{{test_scheduled_task_name}}'
register: remove_task_action_result
@ -262,10 +262,10 @@
assert:
that:
- remove_task_action|changed
- remove_task_action_result.task.actions|count == 1
- remove_task_action_result.task.actions[0].Path == "powershell.exe"
- remove_task_action_result.task.actions[0].Arguments == "-File C:\\ansible\\script.ps1"
- remove_task_action_result.task.actions[0].WorkingDirectory == "C:\\ansible"
- remove_task_action_result.actions|count == 1
- remove_task_action_result.actions[0].path == "powershell.exe"
- remove_task_action_result.actions[0].arguments == "-File C:\\ansible\\script.ps1"
- remove_task_action_result.actions[0].working_directory == "C:\\ansible"
- name: remove task action (idempontent)
win_scheduled_task:
@ -290,7 +290,7 @@
check_mode: yes
- name: get result of remove task (check mode)
test_task_stat:
win_scheduled_task_stat:
path: \
name: '{{test_scheduled_task_name}}'
register: remove_task_result_check
@ -308,7 +308,7 @@
register: remove_task
- name: get result of remove task
test_task_stat:
win_scheduled_task_stat:
path: \
name: '{{test_scheduled_task_name}}'
register: remove_task_result
@ -340,7 +340,7 @@
check_mode: yes
- name: get result of create sole task in folder (check mode)
test_task_stat:
win_scheduled_task_stat:
path: '{{test_scheduled_task_path}}'
name: '{{test_scheduled_task_name}}'
register: create_sole_task_result_check
@ -361,7 +361,7 @@
register: create_sole_task
- name: get result of create sole task in folder
test_task_stat:
win_scheduled_task_stat:
path: '{{test_scheduled_task_path}}'
name: '{{test_scheduled_task_name}}'
register: create_sole_task_result
@ -395,7 +395,7 @@
check_mode: yes
- name: get result of remove sole task in folder (check mode)
test_task_stat:
win_scheduled_task_stat:
path: '{{test_scheduled_task_path}}'
name: '{{test_scheduled_task_name}}'
register: remove_sole_task_result_check
@ -415,7 +415,7 @@
register: remove_sole_task
- name: get result of remove sole task in folder
test_task_stat:
win_scheduled_task_stat:
path: '{{test_scheduled_task_path}}'
name: '{{test_scheduled_task_name}}'
register: remove_sole_task_result

View file

@ -21,7 +21,7 @@
check_mode: yes
- name: get result of task with password principal (check mode)
test_task_stat:
win_scheduled_task_stat:
path: \
name: '{{test_scheduled_task_name}}'
register: task_with_password_result_check
@ -45,7 +45,7 @@
register: task_with_password
- name: get result of task with password principal
test_task_stat:
win_scheduled_task_stat:
path: \
name: '{{test_scheduled_task_name}}'
register: task_with_password_result
@ -55,10 +55,10 @@
that:
- task_with_password|changed
- task_with_password_result.task_exists == True
- task_with_password_result.task.principal.GroupId == None
- task_with_password_result.task.principal.LogonType == "TASK_LOGON_PASSWORD"
- task_with_password_result.task.principal.RunLevel == "TASK_RUNLEVEL_LUA"
- task_with_password_result.task.principal.UserId.endswith(test_scheduled_task_user)
- task_with_password_result.principal.group_id == None
- task_with_password_result.principal.logon_type == "TASK_LOGON_PASSWORD"
- task_with_password_result.principal.run_level == "TASK_RUNLEVEL_LUA"
- task_with_password_result.principal.user_id.endswith(test_scheduled_task_user)
- name: task with password principal (idempotent)
win_scheduled_task:
@ -108,7 +108,7 @@
check_mode: yes
- name: get result of task with s4u principal (check mode)
test_task_stat:
win_scheduled_task_stat:
path: \
name: '{{test_scheduled_task_name}}'
register: task_with_s4u_result_check
@ -118,10 +118,10 @@
that:
- task_with_s4u_check|changed
- task_with_s4u_result_check.task_exists == True
- task_with_s4u_result_check.task.principal.GroupId == None
- task_with_s4u_result_check.task.principal.LogonType == "TASK_LOGON_PASSWORD"
- task_with_s4u_result_check.task.principal.RunLevel == "TASK_RUNLEVEL_LUA"
- task_with_s4u_result_check.task.principal.UserId.endswith(test_scheduled_task_user)
- task_with_s4u_result_check.principal.group_id == None
- task_with_s4u_result_check.principal.logon_type == "TASK_LOGON_PASSWORD"
- task_with_s4u_result_check.principal.run_level == "TASK_RUNLEVEL_LUA"
- task_with_s4u_result_check.principal.user_id.endswith(test_scheduled_task_user)
- name: task with s4u principal
win_scheduled_task:
@ -136,7 +136,7 @@
register: task_with_s4u
- name: get result of task with s4u principal
test_task_stat:
win_scheduled_task_stat:
path: \
name: '{{test_scheduled_task_name}}'
register: task_with_s4u_result
@ -146,10 +146,10 @@
that:
- task_with_s4u|changed
- task_with_s4u_result.task_exists == True
- task_with_s4u_result.task.principal.GroupId == None
- task_with_s4u_result.task.principal.LogonType == "TASK_LOGON_S4U"
- task_with_s4u_result.task.principal.RunLevel == "TASK_RUNLEVEL_LUA"
- task_with_s4u_result.task.principal.UserId.endswith(test_scheduled_task_user)
- task_with_s4u_result.principal.group_id == None
- task_with_s4u_result.principal.logon_type == "TASK_LOGON_S4U"
- task_with_s4u_result.principal.run_level == "TASK_RUNLEVEL_LUA"
- task_with_s4u_result.principal.user_id.endswith(test_scheduled_task_user)
- name: task with s4u principal (idempotent)
win_scheduled_task:
@ -180,7 +180,7 @@
check_mode: yes
- name: get result of task with interactive principal (check mode)
test_task_stat:
win_scheduled_task_stat:
path: \
name: '{{test_scheduled_task_name}}'
register: task_with_interactive_result_check
@ -190,10 +190,10 @@
that:
- task_with_interactive_check|changed
- task_with_interactive_result_check.task_exists == True
- task_with_interactive_result_check.task.principal.GroupId == None
- task_with_interactive_result_check.task.principal.LogonType == "TASK_LOGON_S4U"
- task_with_interactive_result_check.task.principal.RunLevel == "TASK_RUNLEVEL_LUA"
- task_with_interactive_result_check.task.principal.UserId.endswith(test_scheduled_task_user)
- task_with_interactive_result_check.principal.group_id == None
- task_with_interactive_result_check.principal.logon_type == "TASK_LOGON_S4U"
- task_with_interactive_result_check.principal.run_level == "TASK_RUNLEVEL_LUA"
- task_with_interactive_result_check.principal.user_id.endswith(test_scheduled_task_user)
- name: task with interactive principal
win_scheduled_task:
@ -206,7 +206,7 @@
register: task_with_interactive
- name: get result of task with interactive principal
test_task_stat:
win_scheduled_task_stat:
path: \
name: '{{test_scheduled_task_name}}'
register: task_with_interactive_result
@ -216,10 +216,10 @@
that:
- task_with_interactive|changed
- task_with_interactive_result.task_exists == True
- task_with_interactive_result.task.principal.GroupId == None
- task_with_interactive_result.task.principal.LogonType == "TASK_LOGON_INTERACTIVE_TOKEN"
- task_with_interactive_result.task.principal.RunLevel == "TASK_RUNLEVEL_LUA"
- task_with_interactive_result.task.principal.UserId.endswith(test_scheduled_task_user)
- task_with_interactive_result.principal.group_id == None
- task_with_interactive_result.principal.logon_type == "TASK_LOGON_INTERACTIVE_TOKEN"
- task_with_interactive_result.principal.run_level == "TASK_RUNLEVEL_LUA"
- task_with_interactive_result.principal.user_id.endswith(test_scheduled_task_user)
- name: task with interactive principal (idempotent)
win_scheduled_task:
@ -248,7 +248,7 @@
check_mode: yes
- name: get result of task with group principal (check mode)
test_task_stat:
win_scheduled_task_stat:
path: \
name: '{{test_scheduled_task_name}}'
register: task_with_group_result_check
@ -258,10 +258,10 @@
that:
- task_with_group_check|changed
- task_with_group_result_check.task_exists == True
- task_with_group_result_check.task.principal.GroupId == None
- task_with_group_result_check.task.principal.LogonType == "TASK_LOGON_INTERACTIVE_TOKEN"
- task_with_group_result_check.task.principal.RunLevel == "TASK_RUNLEVEL_LUA"
- task_with_group_result_check.task.principal.UserId.endswith(test_scheduled_task_user)
- task_with_group_result_check.principal.group_id == None
- task_with_group_result_check.principal.logon_type == "TASK_LOGON_INTERACTIVE_TOKEN"
- task_with_group_result_check.principal.run_level == "TASK_RUNLEVEL_LUA"
- task_with_group_result_check.principal.user_id.endswith(test_scheduled_task_user)
- name: task with group principal
win_scheduled_task:
@ -274,7 +274,7 @@
register: task_with_group
- name: get result of task with group principal
test_task_stat:
win_scheduled_task_stat:
path: \
name: '{{test_scheduled_task_name}}'
register: task_with_group_result
@ -284,10 +284,10 @@
that:
- task_with_group|changed
- task_with_group_result.task_exists == True
- task_with_group_result.task.principal.GroupId == "BUILTIN\\Administrators"
- task_with_group_result.task.principal.LogonType == "TASK_LOGON_GROUP"
- task_with_group_result.task.principal.RunLevel == "TASK_RUNLEVEL_LUA"
- task_with_group_result.task.principal.UserId == None
- task_with_group_result.principal.group_id == "BUILTIN\\Administrators"
- task_with_group_result.principal.logon_type == "TASK_LOGON_GROUP"
- task_with_group_result.principal.run_level == "TASK_RUNLEVEL_LUA"
- task_with_group_result.principal.user_id == None
- name: task with group principal (idempotent)
win_scheduled_task:
@ -316,7 +316,7 @@
check_mode: yes
- name: get result of task with service account principal (check mode)
test_task_stat:
win_scheduled_task_stat:
path: \
name: '{{test_scheduled_task_name}}'
register: task_with_service_result_check
@ -326,10 +326,10 @@
that:
- task_with_service_check|changed
- task_with_service_result_check.task_exists == True
- task_with_service_result_check.task.principal.GroupId == "BUILTIN\\Administrators"
- task_with_service_result_check.task.principal.LogonType == "TASK_LOGON_GROUP"
- task_with_service_result_check.task.principal.RunLevel == "TASK_RUNLEVEL_LUA"
- task_with_service_result_check.task.principal.UserId == None
- task_with_service_result_check.principal.group_id == "BUILTIN\\Administrators"
- task_with_service_result_check.principal.logon_type == "TASK_LOGON_GROUP"
- task_with_service_result_check.principal.run_level == "TASK_RUNLEVEL_LUA"
- task_with_service_result_check.principal.user_id == None
- name: task with service account principal
win_scheduled_task:
@ -342,7 +342,7 @@
register: task_with_service
- name: get result of task with service account principal
test_task_stat:
win_scheduled_task_stat:
path: \
name: '{{test_scheduled_task_name}}'
register: task_with_service_result
@ -352,10 +352,10 @@
that:
- task_with_service|changed
- task_with_service_result.task_exists == True
- task_with_service_result.task.principal.GroupId == None
- task_with_service_result.task.principal.LogonType == "TASK_LOGON_SERVICE_ACCOUNT"
- task_with_service_result.task.principal.RunLevel == "TASK_RUNLEVEL_LUA"
- task_with_service_result.task.principal.UserId == "NT AUTHORITY\\SYSTEM"
- task_with_service_result.principal.group_id == None
- task_with_service_result.principal.logon_type == "TASK_LOGON_SERVICE_ACCOUNT"
- task_with_service_result.principal.run_level == "TASK_RUNLEVEL_LUA"
- task_with_service_result.principal.user_id == "NT AUTHORITY\\SYSTEM"
- name: task with service account principal (idempotent)
win_scheduled_task:
@ -385,7 +385,7 @@
check_mode: yes
- name: get result of task with highest privilege (check mode)
test_task_stat:
win_scheduled_task_stat:
path: \
name: '{{test_scheduled_task_name}}'
register: task_with_highest_privilege_result_check
@ -394,7 +394,7 @@
assert:
that:
- task_with_highest_privilege_check|changed
- task_with_highest_privilege_result_check.task.principal.RunLevel == "TASK_RUNLEVEL_LUA"
- task_with_highest_privilege_result_check.principal.run_level == "TASK_RUNLEVEL_LUA"
- name: task with highest privilege
win_scheduled_task:
@ -408,7 +408,7 @@
register: task_with_highest_privilege
- name: get result of task with highest privilege
test_task_stat:
win_scheduled_task_stat:
path: \
name: '{{test_scheduled_task_name}}'
register: task_with_highest_privilege_result
@ -417,7 +417,7 @@
assert:
that:
- task_with_highest_privilege|changed
- task_with_highest_privilege_result.task.principal.RunLevel == "TASK_RUNLEVEL_HIGHEST"
- task_with_highest_privilege_result.principal.run_level == "TASK_RUNLEVEL_HIGHEST"
- name: task with highest privilege (idempotent)
win_scheduled_task:

View file

@ -11,7 +11,7 @@
check_mode: yes
- name: get result of create boot trigger (check mode)
test_task_stat:
win_scheduled_task_stat:
path: \
name: '{{test_scheduled_task_name}}'
register: trigger_boot_result_check
@ -33,7 +33,7 @@
register: trigger_boot
- name: get result of create boot trigger
test_task_stat:
win_scheduled_task_stat:
path: \
name: '{{test_scheduled_task_name}}'
register: trigger_boot_result
@ -43,11 +43,11 @@
that:
- trigger_boot|changed
- trigger_boot_result.task_exists == True
- trigger_boot_result.task.triggers|count == 1
- trigger_boot_result.task.triggers[0].Type == "TASK_TRIGGER_BOOT"
- trigger_boot_result.task.triggers[0].Enabled == True
- trigger_boot_result.task.triggers[0].StartBoundary == None
- trigger_boot_result.task.triggers[0].EndBoundary == None
- trigger_boot_result.triggers|count == 1
- trigger_boot_result.triggers[0].type == "TASK_TRIGGER_BOOT"
- trigger_boot_result.triggers[0].enabled == True
- trigger_boot_result.triggers[0].start_boundary == None
- trigger_boot_result.triggers[0].end_boundary == None
- name: create boot trigger (idempotent)
win_scheduled_task:
@ -77,7 +77,7 @@
check_mode: yes
- name: get result of create daily trigger (check mode)
test_task_stat:
win_scheduled_task_stat:
path: \
name: '{{test_scheduled_task_name}}'
register: trigger_daily_result_check
@ -87,11 +87,11 @@
that:
- trigger_daily_check|changed
- trigger_daily_result_check.task_exists == True
- trigger_daily_result_check.task.triggers|count == 1
- trigger_daily_result_check.task.triggers[0].Type == "TASK_TRIGGER_BOOT"
- trigger_daily_result_check.task.triggers[0].Enabled == True
- trigger_daily_result_check.task.triggers[0].StartBoundary == None
- trigger_daily_result_check.task.triggers[0].EndBoundary == None
- trigger_daily_result_check.triggers|count == 1
- trigger_daily_result_check.triggers[0].type == "TASK_TRIGGER_BOOT"
- trigger_daily_result_check.triggers[0].enabled == True
- trigger_daily_result_check.triggers[0].start_boundary == None
- trigger_daily_result_check.triggers[0].end_boundary == None
- name: create daily trigger
win_scheduled_task:
@ -105,7 +105,7 @@
register: trigger_daily
- name: get result of create daily trigger
test_task_stat:
win_scheduled_task_stat:
path: \
name: '{{test_scheduled_task_name}}'
register: trigger_daily_result
@ -115,11 +115,11 @@
that:
- trigger_daily|changed
- trigger_daily_result.task_exists == True
- trigger_daily_result.task.triggers|count == 1
- trigger_daily_result.task.triggers[0].Type == "TASK_TRIGGER_DAILY"
- trigger_daily_result.task.triggers[0].Enabled == True
- trigger_daily_result.task.triggers[0].StartBoundary == "2000-01-01T00:00:01"
- trigger_daily_result.task.triggers[0].EndBoundary == None
- trigger_daily_result.triggers|count == 1
- trigger_daily_result.triggers[0].type == "TASK_TRIGGER_DAILY"
- trigger_daily_result.triggers[0].enabled == True
- trigger_daily_result.triggers[0].start_boundary == "2000-01-01T00:00:01"
- trigger_daily_result.triggers[0].end_boundary == None
- name: create daily trigger (idempotent)
win_scheduled_task:
@ -149,7 +149,7 @@
check_mode: yes
- name: get result of create logon trigger (check mode)
test_task_stat:
win_scheduled_task_stat:
path: \
name: '{{test_scheduled_task_name}}'
register: trigger_logon_result_check
@ -159,11 +159,11 @@
that:
- trigger_logon_check|changed
- trigger_logon_result_check.task_exists == True
- trigger_logon_result_check.task.triggers|count == 1
- trigger_logon_result_check.task.triggers[0].Type == "TASK_TRIGGER_DAILY"
- trigger_logon_result_check.task.triggers[0].Enabled == True
- trigger_logon_result_check.task.triggers[0].StartBoundary == "2000-01-01T00:00:01"
- trigger_logon_result_check.task.triggers[0].EndBoundary == None
- trigger_logon_result_check.triggers|count == 1
- trigger_logon_result_check.triggers[0].type == "TASK_TRIGGER_DAILY"
- trigger_logon_result_check.triggers[0].enabled == True
- trigger_logon_result_check.triggers[0].start_boundary == "2000-01-01T00:00:01"
- trigger_logon_result_check.triggers[0].end_boundary == None
- name: create logon trigger
win_scheduled_task:
@ -176,7 +176,7 @@
register: trigger_logon
- name: get result of create logon trigger
test_task_stat:
win_scheduled_task_stat:
path: \
name: '{{test_scheduled_task_name}}'
register: trigger_logon_result
@ -186,11 +186,11 @@
that:
- trigger_logon|changed
- trigger_logon_result.task_exists == True
- trigger_logon_result.task.triggers|count == 1
- trigger_logon_result.task.triggers[0].Type == "TASK_TRIGGER_LOGON"
- trigger_logon_result.task.triggers[0].Enabled == True
- trigger_logon_result.task.triggers[0].StartBoundary == None
- trigger_logon_result.task.triggers[0].EndBoundary == None
- trigger_logon_result.triggers|count == 1
- trigger_logon_result.triggers[0].type == "TASK_TRIGGER_LOGON"
- trigger_logon_result.triggers[0].enabled == True
- trigger_logon_result.triggers[0].start_boundary == None
- trigger_logon_result.triggers[0].end_boundary == None
- name: create logon trigger (idempotent)
win_scheduled_task:
@ -222,7 +222,7 @@
check_mode: yes
- name: get result of create monthly dow trigger (check mode)
test_task_stat:
win_scheduled_task_stat:
path: \
name: '{{test_scheduled_task_name}}'
register: trigger_monthlydow_result_check
@ -232,11 +232,11 @@
that:
- trigger_monthlydow_check|changed
- trigger_monthlydow_result_check.task_exists == True
- trigger_monthlydow_result_check.task.triggers|count == 1
- trigger_monthlydow_result_check.task.triggers[0].Type == "TASK_TRIGGER_LOGON"
- trigger_monthlydow_result_check.task.triggers[0].Enabled == True
- trigger_monthlydow_result_check.task.triggers[0].StartBoundary == None
- trigger_monthlydow_result_check.task.triggers[0].EndBoundary == None
- trigger_monthlydow_result_check.triggers|count == 1
- trigger_monthlydow_result_check.triggers[0].type == "TASK_TRIGGER_LOGON"
- trigger_monthlydow_result_check.triggers[0].enabled == True
- trigger_monthlydow_result_check.triggers[0].start_boundary == None
- trigger_monthlydow_result_check.triggers[0].end_boundary == None
- name: create monthly dow trigger
win_scheduled_task:
@ -252,7 +252,7 @@
register: trigger_monthlydow
- name: get result of create monthly dow trigger
test_task_stat:
win_scheduled_task_stat:
path: \
name: '{{test_scheduled_task_name}}'
register: trigger_monthlydow_result
@ -262,13 +262,13 @@
that:
- trigger_monthlydow|changed
- trigger_monthlydow_result.task_exists == True
- trigger_monthlydow_result.task.triggers|count == 1
- trigger_monthlydow_result.task.triggers[0].Type == "TASK_TRIGGER_MONTHLYDOW"
- trigger_monthlydow_result.task.triggers[0].Enabled == True
- trigger_monthlydow_result.task.triggers[0].StartBoundary == "2000-01-01T00:00:01"
- trigger_monthlydow_result.task.triggers[0].EndBoundary == None
- trigger_monthlydow_result.task.triggers[0].WeeksOfMonth == "1,2"
- trigger_monthlydow_result.task.triggers[0].DaysOfWeek == "monday,wednesday"
- trigger_monthlydow_result.triggers|count == 1
- trigger_monthlydow_result.triggers[0].type == "TASK_TRIGGER_MONTHLYDOW"
- trigger_monthlydow_result.triggers[0].enabled == True
- trigger_monthlydow_result.triggers[0].start_boundary == "2000-01-01T00:00:01"
- trigger_monthlydow_result.triggers[0].end_boundary == None
- trigger_monthlydow_result.triggers[0].weeks_of_month == "1,2"
- trigger_monthlydow_result.triggers[0].days_of_week == "monday,wednesday"
- name: create monthly dow trigger (idempotent)
win_scheduled_task:
@ -310,7 +310,7 @@
check_mode: yes
- name: get result of create task with multiple triggers (check mode)
test_task_stat:
win_scheduled_task_stat:
path: \
name: '{{test_scheduled_task_name}}'
register: create_multiple_triggers_result_check
@ -320,13 +320,13 @@
that:
- create_multiple_triggers_check|changed
- create_multiple_triggers_result_check.task_exists == True
- create_multiple_triggers_result_check.task.triggers|count == 1
- create_multiple_triggers_result_check.task.triggers[0].Type == "TASK_TRIGGER_MONTHLYDOW"
- create_multiple_triggers_result_check.task.triggers[0].Enabled == True
- create_multiple_triggers_result_check.task.triggers[0].StartBoundary == "2000-01-01T00:00:01"
- create_multiple_triggers_result_check.task.triggers[0].EndBoundary == None
- create_multiple_triggers_result_check.task.triggers[0].WeeksOfMonth == "1,2"
- create_multiple_triggers_result_check.task.triggers[0].DaysOfWeek == "monday,wednesday"
- create_multiple_triggers_result_check.triggers|count == 1
- create_multiple_triggers_result_check.triggers[0].type == "TASK_TRIGGER_MONTHLYDOW"
- create_multiple_triggers_result_check.triggers[0].enabled == True
- create_multiple_triggers_result_check.triggers[0].start_boundary == "2000-01-01T00:00:01"
- create_multiple_triggers_result_check.triggers[0].end_boundary == None
- create_multiple_triggers_result_check.triggers[0].weeks_of_month == "1,2"
- create_multiple_triggers_result_check.triggers[0].days_of_week == "monday,wednesday"
- name: create task with multiple triggers
win_scheduled_task:
@ -349,7 +349,7 @@
register: create_multiple_triggers
- name: get result of create task with multiple triggers
test_task_stat:
win_scheduled_task_stat:
path: \
name: '{{test_scheduled_task_name}}'
register: create_multiple_triggers_result
@ -359,19 +359,19 @@
that:
- create_multiple_triggers|changed
- create_multiple_triggers_result.task_exists == True
- create_multiple_triggers_result.task.triggers|count == 2
- create_multiple_triggers_result.task.triggers[0].Type == "TASK_TRIGGER_MONTHLY"
- create_multiple_triggers_result.task.triggers[0].Enabled == True
- create_multiple_triggers_result.task.triggers[0].StartBoundary == "2000-01-01T00:00:01"
- create_multiple_triggers_result.task.triggers[0].EndBoundary == None
- create_multiple_triggers_result.task.triggers[0].DaysOfMonth == "1,5,10,15,20,25,30"
- create_multiple_triggers_result.task.triggers[0].MonthsOfYear == "march,may,july"
- create_multiple_triggers_result.task.triggers[0].RunOnLastDayOfMonth == True
- create_multiple_triggers_result.task.triggers[1].Type == "TASK_TRIGGER_TIME"
- create_multiple_triggers_result.task.triggers[1].Enabled == True
- create_multiple_triggers_result.task.triggers[1].StartBoundary == "2000-01-01T00:00:01"
- create_multiple_triggers_result.task.triggers[1].EndBoundary == None
- create_multiple_triggers_result.task.triggers[1].RandomDelay == "PT10M5S"
- create_multiple_triggers_result.triggers|count == 2
- create_multiple_triggers_result.triggers[0].type == "TASK_TRIGGER_MONTHLY"
- create_multiple_triggers_result.triggers[0].enabled == True
- create_multiple_triggers_result.triggers[0].start_boundary == "2000-01-01T00:00:01"
- create_multiple_triggers_result.triggers[0].end_boundary == None
- create_multiple_triggers_result.triggers[0].days_of_month == "1,5,10,15,20,25,30"
- create_multiple_triggers_result.triggers[0].months_of_year == "march,may,july"
- create_multiple_triggers_result.triggers[0].run_on_last_day_of_month == True
- create_multiple_triggers_result.triggers[1].type == "TASK_TRIGGER_TIME"
- create_multiple_triggers_result.triggers[1].enabled == True
- create_multiple_triggers_result.triggers[1].start_boundary == "2000-01-01T00:00:01"
- create_multiple_triggers_result.triggers[1].end_boundary == None
- create_multiple_triggers_result.triggers[1].random_delay == "PT10M5S"
- name: create task with multiple triggers (idempotent)
win_scheduled_task:
@ -414,7 +414,7 @@
check_mode: yes
- name: get result of change task with multiple triggers (check mode)
test_task_stat:
win_scheduled_task_stat:
path: \
name: '{{test_scheduled_task_name}}'
register: change_multiple_triggers_result_check
@ -424,19 +424,19 @@
that:
- change_multiple_triggers_check|changed
- change_multiple_triggers_result_check.task_exists == True
- change_multiple_triggers_result_check.task.triggers|count == 2
- change_multiple_triggers_result_check.task.triggers[0].Type == "TASK_TRIGGER_MONTHLY"
- change_multiple_triggers_result_check.task.triggers[0].Enabled == True
- change_multiple_triggers_result_check.task.triggers[0].StartBoundary == "2000-01-01T00:00:01"
- change_multiple_triggers_result_check.task.triggers[0].EndBoundary == None
- change_multiple_triggers_result_check.task.triggers[0].DaysOfMonth == "1,5,10,15,20,25,30"
- change_multiple_triggers_result_check.task.triggers[0].MonthsOfYear == "march,may,july"
- change_multiple_triggers_result_check.task.triggers[0].RunOnLastDayOfMonth == True
- change_multiple_triggers_result_check.task.triggers[1].Type == "TASK_TRIGGER_TIME"
- change_multiple_triggers_result_check.task.triggers[1].Enabled == True
- change_multiple_triggers_result_check.task.triggers[1].StartBoundary == "2000-01-01T00:00:01"
- change_multiple_triggers_result_check.task.triggers[1].EndBoundary == None
- change_multiple_triggers_result_check.task.triggers[1].RandomDelay == "PT10M5S"
- change_multiple_triggers_result_check.triggers|count == 2
- change_multiple_triggers_result_check.triggers[0].type == "TASK_TRIGGER_MONTHLY"
- change_multiple_triggers_result_check.triggers[0].enabled == True
- change_multiple_triggers_result_check.triggers[0].start_boundary == "2000-01-01T00:00:01"
- change_multiple_triggers_result_check.triggers[0].end_boundary == None
- change_multiple_triggers_result_check.triggers[0].days_of_month == "1,5,10,15,20,25,30"
- change_multiple_triggers_result_check.triggers[0].months_of_year == "march,may,july"
- change_multiple_triggers_result_check.triggers[0].run_on_last_day_of_month == True
- change_multiple_triggers_result_check.triggers[1].type == "TASK_TRIGGER_TIME"
- change_multiple_triggers_result_check.triggers[1].enabled == True
- change_multiple_triggers_result_check.triggers[1].start_boundary == "2000-01-01T00:00:01"
- change_multiple_triggers_result_check.triggers[1].end_boundary == None
- change_multiple_triggers_result_check.triggers[1].random_delay == "PT10M5S"
- name: change task with multiple triggers
win_scheduled_task:
@ -453,7 +453,7 @@
register: change_multiple_triggers
- name: get result of change task with multiple triggers
test_task_stat:
win_scheduled_task_stat:
path: \
name: '{{test_scheduled_task_name}}'
register: change_multiple_triggers_result
@ -463,16 +463,16 @@
that:
- change_multiple_triggers|changed
- change_multiple_triggers_result.task_exists == True
- change_multiple_triggers_result.task.triggers|count == 2
- change_multiple_triggers_result.task.triggers[0].Type == "TASK_TRIGGER_WEEKLY"
- change_multiple_triggers_result.task.triggers[0].Enabled == True
- change_multiple_triggers_result.task.triggers[0].StartBoundary == "2000-01-01T00:00:01"
- change_multiple_triggers_result.task.triggers[0].EndBoundary == None
- change_multiple_triggers_result.task.triggers[0].DaysOfWeek == "tuesday,friday"
- change_multiple_triggers_result.task.triggers[1].Type == "TASK_TRIGGER_REGISTRATION"
- change_multiple_triggers_result.task.triggers[1].Enabled == False
- change_multiple_triggers_result.task.triggers[1].StartBoundary == None
- change_multiple_triggers_result.task.triggers[1].EndBoundary == None
- change_multiple_triggers_result.triggers|count == 2
- change_multiple_triggers_result.triggers[0].type == "TASK_TRIGGER_WEEKLY"
- change_multiple_triggers_result.triggers[0].enabled == True
- change_multiple_triggers_result.triggers[0].start_boundary == "2000-01-01T00:00:01"
- change_multiple_triggers_result.triggers[0].end_boundary == None
- change_multiple_triggers_result.triggers[0].days_of_week == "tuesday,friday"
- change_multiple_triggers_result.triggers[1].type == "TASK_TRIGGER_REGISTRATION"
- change_multiple_triggers_result.triggers[1].enabled == False
- change_multiple_triggers_result.triggers[1].start_boundary == None
- change_multiple_triggers_result.triggers[1].end_boundary == None
- name: change task with multiple triggers (idempotent)
win_scheduled_task:
@ -506,7 +506,7 @@
check_mode: yes
- name: get result of remove trigger from multiple triggers (check mode)
test_task_stat:
win_scheduled_task_stat:
path: \
name: '{{test_scheduled_task_name}}'
register: remove_single_trigger_result_check
@ -516,16 +516,16 @@
that:
- remove_single_trigger_check|changed
- remove_single_trigger_result_check.task_exists == True
- remove_single_trigger_result_check.task.triggers|count == 2
- remove_single_trigger_result_check.task.triggers[0].Type == "TASK_TRIGGER_WEEKLY"
- remove_single_trigger_result_check.task.triggers[0].Enabled == True
- remove_single_trigger_result_check.task.triggers[0].StartBoundary == "2000-01-01T00:00:01"
- remove_single_trigger_result_check.task.triggers[0].EndBoundary == None
- remove_single_trigger_result_check.task.triggers[0].DaysOfWeek == "tuesday,friday"
- remove_single_trigger_result_check.task.triggers[1].Type == "TASK_TRIGGER_REGISTRATION"
- remove_single_trigger_result_check.task.triggers[1].Enabled == False
- remove_single_trigger_result_check.task.triggers[1].StartBoundary == None
- remove_single_trigger_result_check.task.triggers[1].EndBoundary == None
- remove_single_trigger_result_check.triggers|count == 2
- remove_single_trigger_result_check.triggers[0].type == "TASK_TRIGGER_WEEKLY"
- remove_single_trigger_result_check.triggers[0].enabled == True
- remove_single_trigger_result_check.triggers[0].start_boundary == "2000-01-01T00:00:01"
- remove_single_trigger_result_check.triggers[0].end_boundary == None
- remove_single_trigger_result_check.triggers[0].days_of_week == "tuesday,friday"
- remove_single_trigger_result_check.triggers[1].type == "TASK_TRIGGER_REGISTRATION"
- remove_single_trigger_result_check.triggers[1].enabled == False
- remove_single_trigger_result_check.triggers[1].start_boundary == None
- remove_single_trigger_result_check.triggers[1].end_boundary == None
- name: remove trigger from multiple triggers
win_scheduled_task:
@ -539,7 +539,7 @@
register: remove_single_trigger
- name: get result of remove trigger from multiple triggers
test_task_stat:
win_scheduled_task_stat:
path: \
name: '{{test_scheduled_task_name}}'
register: remove_single_trigger_result
@ -549,11 +549,11 @@
that:
- remove_single_trigger|changed
- remove_single_trigger_result.task_exists == True
- remove_single_trigger_result.task.triggers|count == 1
- remove_single_trigger_result.task.triggers[0].Type == "TASK_TRIGGER_REGISTRATION"
- remove_single_trigger_result.task.triggers[0].Enabled == False
- remove_single_trigger_result.task.triggers[0].StartBoundary == None
- remove_single_trigger_result.task.triggers[0].EndBoundary == None
- remove_single_trigger_result.triggers|count == 1
- remove_single_trigger_result.triggers[0].type == "TASK_TRIGGER_REGISTRATION"
- remove_single_trigger_result.triggers[0].enabled == False
- remove_single_trigger_result.triggers[0].start_boundary == None
- remove_single_trigger_result.triggers[0].end_boundary == None
- name: remove trigger from multiple triggers (idempotent)
win_scheduled_task:
@ -582,7 +582,7 @@
check_mode: yes
- name: get result of remove all triggers (check mode)
test_task_stat:
win_scheduled_task_stat:
path: \
name: '{{test_scheduled_task_name}}'
register: remove_triggers_result_check
@ -592,11 +592,11 @@
that:
- remove_triggers_check|changed
- remove_triggers_result_check.task_exists == True
- remove_triggers_result_check.task.triggers|count == 1
- remove_triggers_result_check.task.triggers[0].Type == "TASK_TRIGGER_REGISTRATION"
- remove_triggers_result_check.task.triggers[0].Enabled == False
- remove_triggers_result_check.task.triggers[0].StartBoundary == None
- remove_triggers_result_check.task.triggers[0].EndBoundary == None
- remove_triggers_result_check.triggers|count == 1
- remove_triggers_result_check.triggers[0].type == "TASK_TRIGGER_REGISTRATION"
- remove_triggers_result_check.triggers[0].enabled == False
- remove_triggers_result_check.triggers[0].start_boundary == None
- remove_triggers_result_check.triggers[0].end_boundary == None
- name: remove all triggers
win_scheduled_task:
@ -608,7 +608,7 @@
register: remove_triggers
- name: get result of remove all triggers
test_task_stat:
win_scheduled_task_stat:
path: \
name: '{{test_scheduled_task_name}}'
register: remove_triggers_result
@ -618,7 +618,7 @@
that:
- remove_triggers|changed
- remove_triggers_result.task_exists == True
- remove_triggers_result.task.triggers|count == 0
- remove_triggers_result.triggers|count == 0
- name: remove all triggers (idempotent)
win_scheduled_task:

View file

@ -0,0 +1 @@
windows/ci/group3

View file

@ -0,0 +1,3 @@
---
test_scheduled_task_stat_name: Test Task
test_scheduled_task_stat_path: \test path

View file

@ -0,0 +1,150 @@
---
- name: ensure task is deleted before test
win_scheduled_task:
name: '{{test_scheduled_task_stat_name}}'
path: '{{test_scheduled_task_stat_path}}'
state: absent
# folder stat tests
- name: get stat of a folder that is missing
win_scheduled_task_stat:
path: '{{test_scheduled_task_stat_path}}'
register: stat_folder_missing
- name: assert get stat of a folder that is missing
assert:
that:
- stat_folder_missing.folder_exists == False
- name: get stat of existing folder
win_scheduled_task_stat:
path: \
register: stat_folder_present
- name: assert get stat of existing folder
assert:
that:
- stat_folder_present.folder_exists == True
- stat_folder_present.folder_task_count is defined
- stat_folder_present.folder_task_names is defined
- name: create scheduled task in folder
win_scheduled_task:
path: '{{test_scheduled_task_stat_path}}'
name: '{{test_scheduled_task_stat_name}}'
state: present
logon_type: interactive_token
username: Administrator
author: Ansible Author
description: Fake description
execution_time_limit: PT23H
disallow_start_if_on_batteries: false
restart_count: 3
restart_interval: PT15M
actions:
- path: cmd.exe
- path: C:\temp\some.exe
arguments: --help
working_directory: C:\temp
triggers:
- type: boot
delay: PT15M
- type: monthly
days_of_month: 5,15,30
months_of_year: june,december
run_on_last_day_of_month: true
start_boundary: '2017-09-20T03:44:38'
- name: get stat of existing folder with task
win_scheduled_task_stat:
path: '{{test_scheduled_task_stat_path}}'
register: stat_folder_with_task
- name: assert get stat of existing folder with task
assert:
that:
- stat_folder_with_task.folder_exists == True
- stat_folder_with_task.folder_task_count == 1
- stat_folder_with_task.folder_task_names[0] == "Test Task"
- stat_folder_with_task.task_exists is not defined
# task stat tests
- name: get stat of missing task
win_scheduled_task_stat:
path: '{{test_scheduled_task_stat_path}}'
name: fake task
register: stat_task_missing
- name: assert get stat of missing task
assert:
that:
- stat_task_missing.task_exists == False
- name: get stat of existing task
win_scheduled_task_stat:
path: '{{test_scheduled_task_stat_path}}'
name: '{{test_scheduled_task_stat_name}}'
register: stat_task_present
- name: assert get stat of existing task
assert:
that:
- stat_task_present.task_exists == True
- stat_task_present.actions|count == 2
- stat_task_present.actions[0].path == "cmd.exe"
- stat_task_present.actions[0].type == "TASK_ACTION_EXEC"
- stat_task_present.actions[0].working_directory == None
- stat_task_present.actions[1].arguments == "--help"
- stat_task_present.actions[1].path == "C:\\temp\some.exe"
- stat_task_present.actions[1].type == "TASK_ACTION_EXEC"
- stat_task_present.actions[1].working_directory == "C:\\temp"
- stat_task_present.principal.display_name == None
- stat_task_present.principal.group_id == None
- stat_task_present.principal.logon_type == "TASK_LOGON_INTERACTIVE_TOKEN"
- stat_task_present.principal.run_level == "TASK_RUNLEVEL_LUA"
- stat_task_present.principal.user_id.endswith("Administrator")
- stat_task_present.registration_info.author == "Ansible Author"
- stat_task_present.registration_info.date is defined
- stat_task_present.registration_info.description == "Fake description"
- stat_task_present.settings.disallow_start_if_on_batteries == False
- stat_task_present.settings.execution_time_limit == "PT23H"
- stat_task_present.settings.restart_count == 3
- stat_task_present.settings.restart_interval == "PT15M"
- stat_task_present.state.status == "TASK_STATE_READY"
- stat_task_present.triggers|count == 2
- stat_task_present.triggers[0].delay == "PT15M"
- stat_task_present.triggers[0].type == "TASK_TRIGGER_BOOT"
- stat_task_present.triggers[1].days_of_month == "5,15,30"
- stat_task_present.triggers[1].months_of_year == "june,december"
- stat_task_present.triggers[1].run_on_last_day_of_month == True
- stat_task_present.triggers[1].start_boundary == "2017-09-20T03:44:38"
- stat_task_present.triggers[1].type == "TASK_TRIGGER_MONTHLY"
- name: change principal to system account so it will run in the next step
win_scheduled_task:
name: '{{test_scheduled_task_stat_name}}'
path: '{{test_scheduled_task_stat_path}}'
username: SYSTEM
- name: start the scheduled task
win_command: schtasks.exe /Run /TN "{{test_scheduled_task_stat_path}}\{{test_scheduled_task_stat_name}}"
- name: get stat of running task
win_scheduled_task_stat:
path: '{{test_scheduled_task_stat_path}}'
name: '{{test_scheduled_task_stat_name}}'
register: stat_task_running
- name: assert stat of running task
assert:
that:
- stat_task_running.state.status == "TASK_STATE_RUNNING"
- name: stop the scheduled task
win_command: schtasks.exe /End /TN "{{test_scheduled_task_stat_path}}\{{test_scheduled_task_stat_name}}"
- name: ensure task is delete after test
win_scheduled_task:
name: '{{test_scheduled_task_stat_name}}'
path: '{{test_scheduled_task_stat_path}}'
state: absent