win_scheduled_tasks: Improve example test framework (#22833)
Updated as discussed in previous Test Working Group.
This commit is contained in:
parent
866f67e213
commit
ef36d7de68
2 changed files with 113 additions and 39 deletions
|
@ -1,46 +1,21 @@
|
||||||
# NOTE: The win_scheduled_task module only works on Win2012+
|
# NOTE: The win_scheduled_task module only works on Win2012+
|
||||||
|
|
||||||
- name: Test Windows capabilities
|
- name: Test Windows capabilities
|
||||||
raw: Get-Command New-ScheduledTask -ErrorAction SilentlyContinue; $?
|
raw: Get-Command New-ScheduledTask -ErrorAction SilentlyContinue; return $?
|
||||||
failed_when: no
|
failed_when: no
|
||||||
register: new_scheduledtask
|
register: new_scheduledtask
|
||||||
|
|
||||||
- name: Set boolean for capability
|
- name: Only run tests when Windows is capable
|
||||||
set_fact:
|
when: new_scheduledtask.rc == 0
|
||||||
has_new_scheduledtask: '{{ new_scheduledtask.rc == 0 }}'
|
|
||||||
|
|
||||||
- name: Test in normal mode
|
|
||||||
when: has_new_scheduledtask
|
|
||||||
block:
|
block:
|
||||||
- include: tests.yml
|
|
||||||
|
|
||||||
- name: Check the various tasks in normal mode
|
- name: Test in normal mode
|
||||||
assert:
|
include: tests.yml
|
||||||
that:
|
vars:
|
||||||
- add_scheduled_task.changed == true
|
in_check_mode: no
|
||||||
- add_scheduled_task.exists == false
|
|
||||||
- add_scheduled_task_again.changed == false
|
|
||||||
- add_scheduled_task_again.exists == true
|
|
||||||
- remove_scheduled_task.changed == true
|
|
||||||
- remove_scheduled_task.exists == true
|
|
||||||
- remove_scheduled_task_again.changed == false
|
|
||||||
- remove_scheduled_task_again.exists == false
|
|
||||||
|
|
||||||
|
- name: Test in check-mode
|
||||||
- name: Test in check-mode
|
include: tests.yml
|
||||||
check_mode: yes
|
vars:
|
||||||
when: has_new_scheduledtask
|
in_check_mode: yes
|
||||||
block:
|
check_mode: yes
|
||||||
- include: tests.yml
|
|
||||||
|
|
||||||
- name: Check the various tests in check-mode
|
|
||||||
assert:
|
|
||||||
that:
|
|
||||||
- add_scheduled_task.changed == true
|
|
||||||
- add_scheduled_task.exists == false
|
|
||||||
- add_scheduled_task_again.changed == true
|
|
||||||
- add_scheduled_task_again.exists == false
|
|
||||||
- remove_scheduled_task.changed == false
|
|
||||||
- remove_scheduled_task.exists == false
|
|
||||||
- remove_scheduled_task_again.changed == false
|
|
||||||
- remove_scheduled_task_again.exists == false
|
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
- name: Remove potentially leftover scheduled task
|
- name: Remove potentially leftover scheduled task
|
||||||
win_scheduled_task: &wst_absent
|
win_scheduled_task: &wst_absent
|
||||||
name: Test
|
name: Ansible Test
|
||||||
state: absent
|
state: absent
|
||||||
|
|
||||||
|
|
||||||
- name: Add scheduled task
|
- name: Add scheduled task
|
||||||
win_scheduled_task: &wst_present
|
win_scheduled_task: &wst_present
|
||||||
name: Test
|
name: Ansible Test
|
||||||
executable: dir.exe
|
executable: dir.exe
|
||||||
arguments: C:\Windows\Temp\
|
arguments: C:\Windows\Temp\
|
||||||
frequency: once
|
frequency: once
|
||||||
|
@ -13,14 +14,112 @@
|
||||||
user: SYSTEM
|
user: SYSTEM
|
||||||
register: add_scheduled_task
|
register: add_scheduled_task
|
||||||
|
|
||||||
|
- name: Test add_scheduled_task
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- add_scheduled_task.changed == true
|
||||||
|
- add_scheduled_task.exists == false
|
||||||
|
|
||||||
|
|
||||||
- name: Add scheduled task (again)
|
- name: Add scheduled task (again)
|
||||||
win_scheduled_task: *wst_present
|
win_scheduled_task: *wst_present
|
||||||
register: add_scheduled_task_again
|
register: add_scheduled_task_again
|
||||||
|
|
||||||
|
- name: Test add_scheduled_task_again (normal mode)
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- add_scheduled_task_again.changed == false
|
||||||
|
- add_scheduled_task_again.exists == true
|
||||||
|
when: not in_check_mode
|
||||||
|
|
||||||
|
- name: Test add_scheduled_task_again (check-mode)
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- add_scheduled_task_again.changed == true
|
||||||
|
- add_scheduled_task_again.exists == false
|
||||||
|
when: in_check_mode
|
||||||
|
|
||||||
|
|
||||||
|
# FIXME: The below tasks should not require all options
|
||||||
|
# See: https://github.com/ansible/ansible/issues/19279
|
||||||
|
- name: Run tests for normal mode only (expects scheduled task)
|
||||||
|
when: not in_check_mode
|
||||||
|
block:
|
||||||
|
|
||||||
|
- name: Disable scheduled task
|
||||||
|
win_scheduled_task:
|
||||||
|
<<: *wst_present
|
||||||
|
enabled: no
|
||||||
|
register: disable_scheduled_task
|
||||||
|
|
||||||
|
- name: Test disable_scheduled_task
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- disable_scheduled_task.changed == true
|
||||||
|
- disable_scheduled_task.exists == true
|
||||||
|
|
||||||
|
|
||||||
|
- name: Disable scheduled task (again)
|
||||||
|
win_scheduled_task:
|
||||||
|
<<: *wst_present
|
||||||
|
enabled: no
|
||||||
|
register: disable_scheduled_task_again
|
||||||
|
|
||||||
|
- name: Test disable_scheduled_task_again
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- disable_scheduled_task_again.changed == false
|
||||||
|
- disable_scheduled_task_again.exists == true
|
||||||
|
|
||||||
|
|
||||||
|
- name: Enable scheduled task
|
||||||
|
win_scheduled_task:
|
||||||
|
<<: *wst_present
|
||||||
|
enabled: yes
|
||||||
|
register: enable_scheduled_task
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- enable_scheduled_task.changed == true
|
||||||
|
- enable_scheduled_task.exists == true
|
||||||
|
|
||||||
|
- name: Enable scheduled task (again)
|
||||||
|
win_scheduled_task:
|
||||||
|
<<: *wst_present
|
||||||
|
enabled: yes
|
||||||
|
register: enable_scheduled_task_again
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- enable_scheduled_task_again.changed == false
|
||||||
|
- enable_scheduled_task_again.exists == true
|
||||||
|
|
||||||
|
|
||||||
- name: Remove scheduled task
|
- name: Remove scheduled task
|
||||||
win_scheduled_task: *wst_absent
|
win_scheduled_task: *wst_absent
|
||||||
register: remove_scheduled_task
|
register: remove_scheduled_task
|
||||||
|
|
||||||
|
- name: Test remove_scheduled_task (normal mode)
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- remove_scheduled_task.changed == true
|
||||||
|
- remove_scheduled_task.exists == true
|
||||||
|
when: not in_check_mode
|
||||||
|
|
||||||
|
- name: Test remove_scheduled_task (check-mode)
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- remove_scheduled_task.changed == false
|
||||||
|
- remove_scheduled_task.exists == false
|
||||||
|
when: in_check_mode
|
||||||
|
|
||||||
|
|
||||||
- name: Remove scheduled task (again)
|
- name: Remove scheduled task (again)
|
||||||
win_scheduled_task: *wst_absent
|
win_scheduled_task: *wst_absent
|
||||||
register: remove_scheduled_task_again
|
register: remove_scheduled_task_again
|
||||||
|
|
||||||
|
- name: Test remove_scheduled_task_again
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- remove_scheduled_task_again.changed == false
|
||||||
|
- remove_scheduled_task_again.exists == false
|
||||||
|
|
Loading…
Reference in a new issue