Skip to content

Commit 3ef6fbd

Browse files
committed
Add support for Windows Server 2025
1 parent e618a2f commit 3ef6fbd

File tree

5 files changed

+78
-39
lines changed

5 files changed

+78
-39
lines changed

.azure-pipelines/azure-pipelines.yml

+10
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,8 @@ stages:
154154
test: 2022/psrp/https
155155
- name: Server 2022 SSH Key
156156
test: 2022/ssh/key
157+
- name: Server 2025 SSH Key
158+
test: 2025/ssh/key
157159
- stage: Windows_2
158160
displayName: Windows 2
159161
dependsOn:
@@ -174,6 +176,8 @@ stages:
174176
test: 2022/psrp/https
175177
- name: Server 2022 SSH Key
176178
test: 2022/ssh/key
179+
- name: Server 2025 SSH Key
180+
test: 2025/ssh/key
177181
- stage: Windows_3
178182
displayName: Windows 3
179183
dependsOn:
@@ -194,6 +198,8 @@ stages:
194198
test: 2022/psrp/https
195199
- name: Server 2022 SSH Key
196200
test: 2022/ssh/key
201+
- name: Server 2025 SSH Key
202+
test: 2025/ssh/key
197203
- stage: Windows_4
198204
displayName: Windows 4
199205
dependsOn:
@@ -214,6 +220,8 @@ stages:
214220
test: 2022/psrp/https
215221
- name: Server 2022 SSH Key
216222
test: 2022/ssh/key
223+
- name: Server 2025 SSH Key
224+
test: 2025/ssh/key
217225
- stage: Windows_5
218226
displayName: Windows 5
219227
dependsOn:
@@ -234,6 +242,8 @@ stages:
234242
test: 2022/psrp/https
235243
- name: Server 2022 SSH Key
236244
test: 2022/ssh/key
245+
- name: Server 2025 SSH Key
246+
test: 2025/ssh/key
237247
- stage: Summary
238248
condition: succeededOrFailed()
239249
dependsOn:

changelogs/fragments/win-2025.yml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
minor_changes:
2+
- Added support for Windows Server 2025

tests/integration/targets/win_disk_facts/tasks/tests.yml

+20-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,16 @@
1717
- disks_found.ansible_facts.ansible_disks[0].physical_disk.operational_status is defined
1818
- disks_found.ansible_facts.ansible_disks[0].win32_disk_drive is defined
1919
- disks_found.ansible_facts.ansible_disks[0].partitions is defined
20-
- disks_found.ansible_facts.ansible_disks[0].partitions[0].volumes is defined
20+
21+
- name: get C disk partition fact
22+
set_fact:
23+
partition_c: >-
24+
{{ disks_found.ansible_facts.ansible_disks[0].partitions | selectattr('drive_letter', 'equalto', 'C') | first }}
25+
26+
- name: assert disk C partition facts
27+
assert:
28+
that:
29+
- partition_c.volumes is defined
2130

2231
- name: get disk partition facts on the target
2332
win_disk_facts:
@@ -42,9 +51,18 @@
4251
that:
4352
- disks_volumes_found.changed == false
4453
- disks_volumes_found.ansible_facts.ansible_disks[0].partitions is defined
45-
- disks_volumes_found.ansible_facts.ansible_disks[0].partitions[0].volumes is defined
4654

4755

56+
- name: get C disk partition fact
57+
set_fact:
58+
partition_c: >-
59+
{{ disks_found.ansible_facts.ansible_disks[0].partitions | selectattr('drive_letter', 'equalto', 'C') | first }}
60+
61+
- name: assert volume and partition disk facts for C
62+
assert:
63+
that:
64+
- partition_c.volumes is defined
65+
4866
- name: get disk physical_disk facts on the target
4967
win_disk_facts:
5068
filter:

tests/integration/targets/win_format/tasks/tests.yml

+6-4
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,25 @@
2323
- format_mutex_result is failed
2424
- 'format_mutex_result.msg == "parameters are mutually exclusive: drive_letter, path, label"'
2525

26-
- name: Fully format volume and assign label (check)
26+
- name: Format volume and assign label (check)
2727
win_format:
2828
drive_letter: T
2929
new_label: Formatted
30-
full: True
30+
# Fails on Server 2025 with generic error. May be fixed in a future update
31+
# but for now we don't test this scenario.
32+
# full: True
3133
allocation_unit_size: 8192
3234
register: format_result_check
3335
check_mode: True
3436

3537
- ansible.windows.win_shell: $AnsiPart = Get-Partition -DriveLetter T; $AnsiVol = Get-Volume -DriveLetter T; "$($AnsiPart.Size),$($AnsiVol.Size),$($AnsiVol.FileSystemLabel),$((Get-CimInstance -ClassName Win32_Volume -Filter "DriveLetter = 'T:'" -Property BlockSize).BlockSize)"
3638
register: formatted_value_result_check
3739

38-
- name: Fully format volume and assign label
40+
- name: Format volume and assign label
3941
win_format:
4042
drive_letter: T
4143
new_label: Formatted
42-
full: True
44+
# full: True
4345
allocation_unit_size: 8192
4446
register: format_result
4547

Original file line numberDiff line numberDiff line change
@@ -1,25 +1,40 @@
11
# I dislike this but 2008 doesn't support the Win32_PowerPlan WMI provider
2+
- name: set fact for getting plan info
3+
ansible.builtin.set_fact:
4+
plan_info_script: |
5+
$infoPattern = 'Power Scheme GUID: (?<guid>[a-fA-F0-9]{8}-(?>[a-fA-F0-9]{4}-){3}[a-fA-F0-9]{12})\s+\((?<name>.*)\)(?<active>\s+\*)?'
6+
7+
powercfg.exe /list | ForEach-Object {
8+
if ($_ -match $infoPattern) {
9+
[PSCustomObject]@{
10+
name = $Matches['name']
11+
guid = $Matches['guid']
12+
active = (-not [string]::IsNullOrEmpty($Matches['active']))
13+
}
14+
}
15+
} | Sort-Object -Property active -Descending
16+
217
- name: get current plan details
3-
ansible.windows.win_shell: |
4-
$plan_info = powercfg.exe /list
5-
($plan_info | Select-String -Pattern '\(([\w\s]*)\) \*$').Matches.Groups[1].Value
6-
($plan_info | Select-String -Pattern '\(([\w\s]*)\)$').Matches.Groups[1].Value
18+
ansible.windows.win_powershell:
19+
script: '{{ plan_info_script }}'
20+
changed_when: False
721
register: plan_info
822

923
- set_fact:
10-
original_plan: '{{ plan_info.stdout_lines[0] }}'
11-
name: '{{ plan_info.stdout_lines[1] }}'
24+
original_plan: '{{ plan_info.output[0] }}'
25+
new_plan: '{{ plan_info.output[1] }}'
1226

1327
- block:
1428
#Test that plan detects change is needed, but doesn't actually apply change
1529
- name: set power plan (check mode)
1630
win_power_plan:
17-
name: "{{ name }}"
31+
name: "{{ new_plan.name }}"
1832
register: set_plan_check
1933
check_mode: yes
2034

2135
- name: get result of set power plan (check mode)
22-
ansible.windows.win_shell: (powercfg.exe /list | Select-String -Pattern '\({{ name }}\)').Line
36+
ansible.windows.win_powershell:
37+
script: '{{ plan_info_script }}'
2338
register: set_plan_check_result
2439
changed_when: False
2540

@@ -28,29 +43,30 @@
2843
assert:
2944
that:
3045
- set_plan_check is changed
31-
- not set_plan_check_result.stdout_lines[0].endswith('*')
46+
- set_plan_check_result.output[0].guid == original_plan.guid
3247

3348
#Test that setting plan and that change is applied
3449
- name: set power plan
3550
win_power_plan:
36-
name: "{{ name }}"
51+
name: "{{ new_plan.name }}"
3752
register: set_plan
3853

3954
- name: get result of set power plan
40-
ansible.windows.win_shell: (powercfg.exe /list | Select-String -Pattern '\({{ name }}\)').Line
55+
ansible.windows.win_powershell:
56+
script: '{{ plan_info_script }}'
4157
register: set_plan_result
4258
changed_when: False
4359

4460
- name: assert setting plan
4561
assert:
4662
that:
4763
- set_plan is changed
48-
- set_plan_result.stdout_lines[0].endswith('*')
64+
- set_plan_result.output[0].guid == new_plan.guid
4965

5066
#Test that plan doesn't apply change if it is already set
5167
- name: set power plan (idempotent)
5268
win_power_plan:
53-
name: "{{ name }}"
69+
name: "{{ new_plan.name }}"
5470
register: set_plan_idempotent
5571

5672
- name: assert setting plan (idempotent)
@@ -61,29 +77,19 @@
6177
always:
6278
- name: always change back plan to the original when done testing
6379
win_power_plan:
64-
name: '{{ original_plan }}'
65-
66-
- name: get current plan guid details
67-
ansible.windows.win_shell: |
68-
$plan_info = powercfg.exe /list
69-
($plan_info | Select-String -Pattern '([a-z0-9]+\-[a-z0-9]+\-[a-z0-9]+\-[a-z0-9]+\-[a-z0-9]+).+\*').Matches.Groups[1].Value
70-
($plan_info | Select-String -Pattern '([a-z0-9]+\-[a-z0-9]+\-[a-z0-9]+\-[a-z0-9]+\-[a-z0-9]+)').Matches.Groups[1].Value
71-
register: guid_plan_info
72-
73-
- set_fact:
74-
original_plan: '{{ guid_plan_info.stdout_lines[0] }}'
75-
name: '{{ guid_plan_info.stdout_lines[1] }}'
80+
name: '{{ original_plan.name }}'
7681

7782
- block:
7883
#Test that plan detects change is needed, but doesn't actually apply change
7984
- name: set power plan guid (check mode)
8085
win_power_plan:
81-
guid: "{{ name }}"
86+
guid: "{{ new_plan.guid }}"
8287
register: set_plan_check_guid
8388
check_mode: yes
8489

8590
- name: get result of set power plan guid (check mode)
86-
ansible.windows.win_shell: (powercfg.exe /list | Select-String -Pattern '{{ name }}').Line
91+
ansible.windows.win_powershell:
92+
script: '{{ plan_info_script }}'
8793
register: set_plan_check_result_guid
8894
changed_when: False
8995

@@ -92,29 +98,30 @@
9298
assert:
9399
that:
94100
- set_plan_check_guid is changed
95-
- not set_plan_check_result_guid.stdout_lines[0].endswith('*')
101+
- set_plan_check_result_guid.output[0].guid == original_plan.guid
96102

97103
#Test that setting plan and that change is applied
98104
- name: set power plan guid
99105
win_power_plan:
100-
guid: "{{ name }}"
106+
guid: "{{ new_plan.guid }}"
101107
register: set_plan_guid
102108

103109
- name: get result of set power plan guid
104-
ansible.windows.win_shell: (powercfg.exe /list | Select-String -Pattern '{{ name }}').Line
110+
ansible.windows.win_powershell:
111+
script: '{{ plan_info_script }}'
105112
register: set_plan_result_guid
106113
changed_when: False
107114

108115
- name: assert setting plan guid
109116
assert:
110117
that:
111118
- set_plan_guid is changed
112-
- set_plan_result_guid.stdout_lines[0].endswith('*')
119+
- set_plan_result_guid.output[0].guid == new_plan.guid
113120

114121
#Test that plan doesn't apply change if it is already set
115122
- name: set power plan guid (idempotent)
116123
win_power_plan:
117-
guid: "{{ name }}"
124+
guid: "{{ new_plan.guid }}"
118125
register: set_plan_idempotent_guid
119126

120127
- name: assert setting plan guid (idempotent)
@@ -125,4 +132,4 @@
125132
always:
126133
- name: always change back plan to the original when done testing guid
127134
win_power_plan:
128-
guid: '{{ original_plan }}'
135+
guid: '{{ original_plan.guid }}'

0 commit comments

Comments
 (0)