forked from ansible/ansible
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
win_scheduled_task: Added frequency: once and check_mode support (ans…
…ible#22611) * win_scheduled_task: Added frequency: once and check_mode support This patch includes: - Renamed `execute:` parameter to `executable:` - Renamed `argument:` parameter to `arguments:` - Implemented `frequency: once` support - Implemented check_mode support - Fix idempotency issue related to empty description - Added integration tests * Improve the integration test structure I think this is a great way to test normal mode and check-mode from the same playbook. * Small fixes after review
- Loading branch information
1 parent
3449859
commit 72e7927
Showing
5 changed files
with
143 additions
and
76 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
windows/ci/group3 |
46 changes: 46 additions & 0 deletions
46
test/integration/targets/win_scheduled_task/tasks/main.yml
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# NOTE: The win_scheduled_task module only works on Win2012+ | ||
|
||
- name: Test Windows capabilities | ||
raw: Get-Command New-ScheduledTask -ErrorAction SilentlyContinue; $? | ||
failed_when: no | ||
register: new_scheduledtask | ||
|
||
- name: Set boolean for capability | ||
set_fact: | ||
has_new_scheduledtask: '{{ new_scheduledtask.rc == 0 }}' | ||
|
||
- name: Test in normal mode | ||
when: has_new_scheduledtask | ||
block: | ||
- include: tests.yml | ||
|
||
- name: Check the various tasks in normal mode | ||
assert: | ||
that: | ||
- add_scheduled_task.changed == true | ||
- 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 | ||
check_mode: yes | ||
when: has_new_scheduledtask | ||
block: | ||
- 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 |
26 changes: 26 additions & 0 deletions
26
test/integration/targets/win_scheduled_task/tasks/tests.yml
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
- name: Remove potentially leftover scheduled task | ||
win_scheduled_task: &wst_absent | ||
name: Test | ||
state: absent | ||
|
||
- name: Add scheduled task | ||
win_scheduled_task: &wst_present | ||
name: Test | ||
executable: dir.exe | ||
arguments: C:\Windows\Temp\ | ||
frequency: once | ||
time: 5pm | ||
user: SYSTEM | ||
register: add_scheduled_task | ||
|
||
- name: Add scheduled task (again) | ||
win_scheduled_task: *wst_present | ||
register: add_scheduled_task_again | ||
|
||
- name: Remove scheduled task | ||
win_scheduled_task: *wst_absent | ||
register: remove_scheduled_task | ||
|
||
- name: Remove scheduled task (again) | ||
win_scheduled_task: *wst_absent | ||
register: remove_scheduled_task_again |