2019-01-31 21:32:12 +01:00
|
|
|
# I dislike this but 2008 doesn't support the Win32_PowerPlan WMI provider
|
|
|
|
- name: get current plan details
|
|
|
|
win_shell: |
|
|
|
|
$plan_info = powercfg.exe /list
|
|
|
|
($plan_info | Select-String -Pattern '\(([\w\s]*)\) \*$').Matches.Groups[1].Value
|
|
|
|
($plan_info | Select-String -Pattern '\(([\w\s]*)\)$').Matches.Groups[1].Value
|
|
|
|
register: plan_info
|
2017-08-29 22:22:06 +02:00
|
|
|
|
2019-01-31 21:32:12 +01:00
|
|
|
- set_fact:
|
|
|
|
original_plan: '{{ plan_info.stdout_lines[0] }}'
|
|
|
|
name: '{{ plan_info.stdout_lines[1] }}'
|
2017-08-29 22:22:06 +02:00
|
|
|
|
|
|
|
- block:
|
|
|
|
#Test that plan detects change is needed, but doesn't actually apply change
|
|
|
|
- name: set power plan (check mode)
|
|
|
|
win_power_plan:
|
|
|
|
name: "{{ name }}"
|
|
|
|
register: set_plan_check
|
|
|
|
check_mode: yes
|
|
|
|
|
|
|
|
- name: get result of set power plan (check mode)
|
2019-01-31 21:32:12 +01:00
|
|
|
win_shell: (powercfg.exe /list | Select-String -Pattern '\({{ name }}\)').Line
|
2017-08-29 22:22:06 +02:00
|
|
|
register: set_plan_check_result
|
|
|
|
changed_when: False
|
2019-01-31 21:32:12 +01:00
|
|
|
|
2017-08-29 22:22:06 +02:00
|
|
|
# verify that the powershell check is showing the plan as still inactive on the system
|
|
|
|
- name: assert setting plan (check mode)
|
|
|
|
assert:
|
|
|
|
that:
|
2017-11-27 23:58:08 +01:00
|
|
|
- set_plan_check is changed
|
2019-01-31 21:32:12 +01:00
|
|
|
- not set_plan_check_result.stdout_lines[0].endswith('*')
|
2017-08-29 22:22:06 +02:00
|
|
|
|
|
|
|
#Test that setting plan and that change is applied
|
|
|
|
- name: set power plan
|
|
|
|
win_power_plan:
|
|
|
|
name: "{{ name }}"
|
|
|
|
register: set_plan
|
|
|
|
|
|
|
|
- name: get result of set power plan
|
2019-01-31 21:32:12 +01:00
|
|
|
win_shell: (powercfg.exe /list | Select-String -Pattern '\({{ name }}\)').Line
|
2017-08-29 22:22:06 +02:00
|
|
|
register: set_plan_result
|
|
|
|
changed_when: False
|
|
|
|
|
|
|
|
- name: assert setting plan
|
|
|
|
assert:
|
|
|
|
that:
|
2017-11-27 23:58:08 +01:00
|
|
|
- set_plan is changed
|
2019-01-31 21:32:12 +01:00
|
|
|
- set_plan_result.stdout_lines[0].endswith('*')
|
2017-08-29 22:22:06 +02:00
|
|
|
|
|
|
|
#Test that plan doesn't apply change if it is already set
|
|
|
|
- name: set power plan (idempotent)
|
|
|
|
win_power_plan:
|
|
|
|
name: "{{ name }}"
|
|
|
|
register: set_plan_idempotent
|
|
|
|
|
|
|
|
- name: assert setting plan (idempotent)
|
|
|
|
assert:
|
|
|
|
that:
|
2017-11-27 23:58:08 +01:00
|
|
|
- set_plan_idempotent is not changed
|
2017-08-29 22:22:06 +02:00
|
|
|
|
|
|
|
always:
|
2019-01-31 21:32:12 +01:00
|
|
|
- name: always change back plan to the original when done testing
|
2017-08-29 22:22:06 +02:00
|
|
|
win_power_plan:
|
2019-01-31 21:32:12 +01:00
|
|
|
name: '{{ original_plan }}'
|