ansible/test/integration/targets/win_scheduled_task/tasks/triggers.yml
Jordan Borean 838f39e76a win_scheduled_task: rewrite (#28995)
* win_scheduled_task: rewrite for additionality functionality and bug fixes

* fixes for docs and os version differences

* started with the testing

* doc fix

* added more tests

* added principals tests

* finished tests for win_scheduled_task rewrite

* feedback from PR

* change to fail when both new and deprecated args are set

* change diff variable to match new standard and update doc sentance
2017-09-20 10:28:03 +10:00

635 lines
21 KiB
YAML

---
- name: create boot trigger (check mode)
win_scheduled_task:
name: '{{test_scheduled_task_name}}'
state: present
actions:
- path: cmd.exe
triggers:
- type: boot
register: trigger_boot_check
check_mode: yes
- name: get result of create boot trigger (check mode)
test_task_stat:
path: \
name: '{{test_scheduled_task_name}}'
register: trigger_boot_result_check
- name: assert results of create boot trigger (check mode)
assert:
that:
- trigger_boot_check|changed
- trigger_boot_result_check.task_exists == False
- name: create boot trigger
win_scheduled_task:
name: '{{test_scheduled_task_name}}'
state: present
actions:
- path: cmd.exe
triggers:
- type: boot
register: trigger_boot
- name: get result of create boot trigger
test_task_stat:
path: \
name: '{{test_scheduled_task_name}}'
register: trigger_boot_result
- name: assert results of create boot trigger
assert:
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
- name: create boot trigger (idempotent)
win_scheduled_task:
name: '{{test_scheduled_task_name}}'
state: present
actions:
- path: cmd.exe
triggers:
- type: boot
register: trigger_boot_again
- name: assert results of create boot trigger (idempotent)
assert:
that:
- not trigger_boot_again|changed
- name: create daily trigger (check mode)
win_scheduled_task:
name: '{{test_scheduled_task_name}}'
state: present
actions:
- path: cmd.exe
triggers:
- type: daily
start_boundary: '2000-01-01T00:00:01'
register: trigger_daily_check
check_mode: yes
- name: get result of create daily trigger (check mode)
test_task_stat:
path: \
name: '{{test_scheduled_task_name}}'
register: trigger_daily_result_check
- name: assert results of create daily trigger (check mode)
assert:
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
- name: create daily trigger
win_scheduled_task:
name: '{{test_scheduled_task_name}}'
state: present
actions:
- path: cmd.exe
triggers:
- type: daily
start_boundary: '2000-01-01T00:00:01'
register: trigger_daily
- name: get result of create daily trigger
test_task_stat:
path: \
name: '{{test_scheduled_task_name}}'
register: trigger_daily_result
- name: assert results of create daily trigger
assert:
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
- name: create daily trigger (idempotent)
win_scheduled_task:
name: '{{test_scheduled_task_name}}'
state: present
actions:
- path: cmd.exe
triggers:
- type: daily
start_boundary: '2000-01-01T00:00:01'
register: trigger_daily_again
- name: assert results of create daily trigger (idempotent)
assert:
that:
- not trigger_daily_again|changed
- name: create logon trigger (check mode)
win_scheduled_task:
name: '{{test_scheduled_task_name}}'
state: present
actions:
- path: cmd.exe
triggers:
- type: logon
register: trigger_logon_check
check_mode: yes
- name: get result of create logon trigger (check mode)
test_task_stat:
path: \
name: '{{test_scheduled_task_name}}'
register: trigger_logon_result_check
- name: assert results of create logon trigger
assert:
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
- name: create logon trigger
win_scheduled_task:
name: '{{test_scheduled_task_name}}'
state: present
actions:
- path: cmd.exe
triggers:
- type: logon
register: trigger_logon
- name: get result of create logon trigger
test_task_stat:
path: \
name: '{{test_scheduled_task_name}}'
register: trigger_logon_result
- name: assert results of create logon trigger
assert:
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
- name: create logon trigger (idempotent)
win_scheduled_task:
name: '{{test_scheduled_task_name}}'
state: present
actions:
- path: cmd.exe
triggers:
- type: logon
register: trigger_logon_again
- name: assert results of create logon trigger (idempotent)
assert:
that:
- not trigger_logon_again|changed
- name: create monthly dow trigger (check mode)
win_scheduled_task:
name: '{{test_scheduled_task_name}}'
state: present
actions:
- path: cmd.exe
triggers:
- type: monthlydow
start_boundary: '2000-01-01T00:00:01'
weeks_of_month: 1,2
days_of_week: [ "monday", "wednesday" ]
register: trigger_monthlydow_check
check_mode: yes
- name: get result of create monthly dow trigger (check mode)
test_task_stat:
path: \
name: '{{test_scheduled_task_name}}'
register: trigger_monthlydow_result_check
- name: assert results of create monthly dow trigger (check mode)
assert:
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
- name: create monthly dow trigger
win_scheduled_task:
name: '{{test_scheduled_task_name}}'
state: present
actions:
- path: cmd.exe
triggers:
- type: monthlydow
start_boundary: '2000-01-01T00:00:01'
weeks_of_month: 1,2
days_of_week: [ "monday", "wednesday" ]
register: trigger_monthlydow
- name: get result of create monthly dow trigger
test_task_stat:
path: \
name: '{{test_scheduled_task_name}}'
register: trigger_monthlydow_result
- name: assert results of create monthly dow trigger
assert:
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"
- name: create monthly dow trigger (idempotent)
win_scheduled_task:
name: '{{test_scheduled_task_name}}'
state: present
actions:
- path: cmd.exe
triggers:
- type: monthlydow
start_boundary: '2000-01-01T00:00:01'
weeks_of_month: 1,2
days_of_week: [ "monday", "wednesday" ]
register: trigger_monthlydow_again
- name: assert results of create monthly dow trigger (idempotent)
assert:
that:
- not trigger_monthlydow_again|changed
- name: create task with multiple triggers (check mode)
win_scheduled_task:
name: '{{test_scheduled_task_name}}'
state: present
actions:
- path: cmd.exe
triggers:
- type: monthly
days_of_month: 1,5,10,15,20,25,30
run_on_last_day_of_month: true
start_boundary: '2000-01-01T00:00:01'
months_of_year:
- march
- may
- july
- type: time
start_boundary: '2000-01-01T00:00:01'
random_delay: PT10M5S
register: create_multiple_triggers_check
check_mode: yes
- name: get result of create task with multiple triggers (check mode)
test_task_stat:
path: \
name: '{{test_scheduled_task_name}}'
register: create_multiple_triggers_result_check
- name: assert results of create task with multiple triggers (check mode)
assert:
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"
- name: create task with multiple triggers
win_scheduled_task:
name: '{{test_scheduled_task_name}}'
state: present
actions:
- path: cmd.exe
triggers:
- type: monthly
days_of_month: 1,5,10,15,20,25,30
run_on_last_day_of_month: true
start_boundary: '2000-01-01T00:00:01'
months_of_year:
- march
- may
- july
- type: time
start_boundary: '2000-01-01T00:00:01'
random_delay: PT10M5S
register: create_multiple_triggers
- name: get result of create task with multiple triggers
test_task_stat:
path: \
name: '{{test_scheduled_task_name}}'
register: create_multiple_triggers_result
- name: assert results of create task with multiple triggers
assert:
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"
- name: create task with multiple triggers (idempotent)
win_scheduled_task:
name: '{{test_scheduled_task_name}}'
state: present
actions:
- path: cmd.exe
triggers:
- type: monthly
days_of_month: 1,5,10,15,20,25,30
run_on_last_day_of_month: true
start_boundary: '2000-01-01T00:00:01'
months_of_year:
- march
- may
- july
- type: time
start_boundary: '2000-01-01T00:00:01'
random_delay: PT10M5S
register: create_multiple_triggers_again
- name: assert results of create task with multiple triggers (idempotent)
assert:
that:
- not create_multiple_triggers_again|changed
- name: change task with multiple triggers (check mode)
win_scheduled_task:
name: '{{test_scheduled_task_name}}'
state: present
actions:
- path: cmd.exe
triggers:
- type: weekly
days_of_week: tuesday,friday
start_boundary: '2000-01-01T00:00:01'
- type: registration
enabled: no
register: change_multiple_triggers_check
check_mode: yes
- name: get result of change task with multiple triggers (check mode)
test_task_stat:
path: \
name: '{{test_scheduled_task_name}}'
register: change_multiple_triggers_result_check
- name: assert results of change task with multiple triggers (check mode)
assert:
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"
- name: change task with multiple triggers
win_scheduled_task:
name: '{{test_scheduled_task_name}}'
state: present
actions:
- path: cmd.exe
triggers:
- type: weekly
days_of_week: tuesday,friday
start_boundary: '2000-01-01T00:00:01'
- type: registration
enabled: no
register: change_multiple_triggers
- name: get result of change task with multiple triggers
test_task_stat:
path: \
name: '{{test_scheduled_task_name}}'
register: change_multiple_triggers_result
- name: assert results of change task with multiple triggers
assert:
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
- name: change task with multiple triggers (idempotent)
win_scheduled_task:
name: '{{test_scheduled_task_name}}'
state: present
actions:
- path: cmd.exe
triggers:
- type: weekly
days_of_week: tuesday,friday
start_boundary: '2000-01-01T00:00:01'
- type: registration
enabled: no
register: change_multiple_triggers_again
- name: assert results of change task with multiple triggers (idempotent)
assert:
that:
- not change_multiple_triggers_again|changed
- name: remove trigger from multiple triggers (check mode)
win_scheduled_task:
name: '{{test_scheduled_task_name}}'
state: present
actions:
- path: cmd.exe
triggers:
- type: registration
enabled: no
register: remove_single_trigger_check
check_mode: yes
- name: get result of remove trigger from multiple triggers (check mode)
test_task_stat:
path: \
name: '{{test_scheduled_task_name}}'
register: remove_single_trigger_result_check
- name: assert results of remove trigger from multiple triggers (check mode)
assert:
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
- name: remove trigger from multiple triggers
win_scheduled_task:
name: '{{test_scheduled_task_name}}'
state: present
actions:
- path: cmd.exe
triggers:
- type: registration
enabled: no
register: remove_single_trigger
- name: get result of remove trigger from multiple triggers
test_task_stat:
path: \
name: '{{test_scheduled_task_name}}'
register: remove_single_trigger_result
- name: assert results of remove trigger from multiple triggers
assert:
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
- name: remove trigger from multiple triggers (idempotent)
win_scheduled_task:
name: '{{test_scheduled_task_name}}'
state: present
actions:
- path: cmd.exe
triggers:
- type: registration
enabled: no
register: remove_single_trigger_again
- name: assert results of remove trigger from multiple triggers (idempotent)
assert:
that:
- not remove_single_trigger_again|changed
- name: remove all triggers (check mode)
win_scheduled_task:
name: '{{test_scheduled_task_name}}'
state: present
actions:
- path: cmd.exe
triggers: []
register: remove_triggers_check
check_mode: yes
- name: get result of remove all triggers (check mode)
test_task_stat:
path: \
name: '{{test_scheduled_task_name}}'
register: remove_triggers_result_check
- name: assert results of remove all triggers (check mode)
assert:
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
- name: remove all triggers
win_scheduled_task:
name: '{{test_scheduled_task_name}}'
state: present
actions:
- path: cmd.exe
triggers: []
register: remove_triggers
- name: get result of remove all triggers
test_task_stat:
path: \
name: '{{test_scheduled_task_name}}'
register: remove_triggers_result
- name: assert results of remove all triggers
assert:
that:
- remove_triggers|changed
- remove_triggers_result.task_exists == True
- remove_triggers_result.task.triggers|count == 0
- name: remove all triggers (idempotent)
win_scheduled_task:
name: '{{test_scheduled_task_name}}'
state: present
actions:
- path: cmd.exe
triggers: []
register: remove_triggers_again
- name: assert results of remove all triggers (idempotent)
assert:
that:
- not remove_triggers_again|changed