Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Windows Server 2025 #590

Merged
merged 1 commit into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .azure-pipelines/azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ stages:
test: 2022/psrp/https
- name: Server 2022 SSH Key
test: 2022/ssh/key
- name: Server 2025 SSH Key
test: 2025/ssh/key
- stage: Windows_2
displayName: Windows 2
dependsOn:
Expand All @@ -174,6 +176,8 @@ stages:
test: 2022/psrp/https
- name: Server 2022 SSH Key
test: 2022/ssh/key
- name: Server 2025 SSH Key
test: 2025/ssh/key
- stage: Windows_3
displayName: Windows 3
dependsOn:
Expand All @@ -194,6 +198,8 @@ stages:
test: 2022/psrp/https
- name: Server 2022 SSH Key
test: 2022/ssh/key
- name: Server 2025 SSH Key
test: 2025/ssh/key
- stage: Windows_4
displayName: Windows 4
dependsOn:
Expand All @@ -214,6 +220,8 @@ stages:
test: 2022/psrp/https
- name: Server 2022 SSH Key
test: 2022/ssh/key
- name: Server 2025 SSH Key
test: 2025/ssh/key
- stage: Windows_5
displayName: Windows 5
dependsOn:
Expand All @@ -234,6 +242,8 @@ stages:
test: 2022/psrp/https
- name: Server 2022 SSH Key
test: 2022/ssh/key
- name: Server 2025 SSH Key
test: 2025/ssh/key
- stage: Summary
condition: succeededOrFailed()
dependsOn:
Expand Down
2 changes: 2 additions & 0 deletions changelogs/fragments/win-2025.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- Added support for Windows Server 2025
22 changes: 20 additions & 2 deletions tests/integration/targets/win_disk_facts/tasks/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,16 @@
- disks_found.ansible_facts.ansible_disks[0].physical_disk.operational_status is defined
- disks_found.ansible_facts.ansible_disks[0].win32_disk_drive is defined
- disks_found.ansible_facts.ansible_disks[0].partitions is defined
- disks_found.ansible_facts.ansible_disks[0].partitions[0].volumes is defined

- name: get C disk partition fact
set_fact:
partition_c: >-
{{ disks_found.ansible_facts.ansible_disks[0].partitions | selectattr('drive_letter', 'equalto', 'C') | first }}

- name: assert disk C partition facts
assert:
that:
- partition_c.volumes is defined

- name: get disk partition facts on the target
win_disk_facts:
Expand All @@ -42,9 +51,18 @@
that:
- disks_volumes_found.changed == false
- disks_volumes_found.ansible_facts.ansible_disks[0].partitions is defined
- disks_volumes_found.ansible_facts.ansible_disks[0].partitions[0].volumes is defined


- name: get C disk partition fact
set_fact:
partition_c: >-
{{ disks_found.ansible_facts.ansible_disks[0].partitions | selectattr('drive_letter', 'equalto', 'C') | first }}

- name: assert volume and partition disk facts for C
assert:
that:
- partition_c.volumes is defined

- name: get disk physical_disk facts on the target
win_disk_facts:
filter:
Expand Down
10 changes: 6 additions & 4 deletions tests/integration/targets/win_format/tasks/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,25 @@
- format_mutex_result is failed
- 'format_mutex_result.msg == "parameters are mutually exclusive: drive_letter, path, label"'

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

- 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)"
register: formatted_value_result_check

- name: Fully format volume and assign label
- name: Format volume and assign label
win_format:
drive_letter: T
new_label: Formatted
full: True
# full: True
allocation_unit_size: 8192
register: format_result

Expand Down
73 changes: 40 additions & 33 deletions tests/integration/targets/win_power_plan/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,40 @@
# I dislike this but 2008 doesn't support the Win32_PowerPlan WMI provider
- name: set fact for getting plan info
ansible.builtin.set_fact:
plan_info_script: |
$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+\*)?'

powercfg.exe /list | ForEach-Object {
if ($_ -match $infoPattern) {
[PSCustomObject]@{
name = $Matches['name']
guid = $Matches['guid']
active = (-not [string]::IsNullOrEmpty($Matches['active']))
}
}
} | Sort-Object -Property active -Descending

- name: get current plan details
ansible.windows.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
ansible.windows.win_powershell:
script: '{{ plan_info_script }}'
changed_when: False
register: plan_info

- set_fact:
original_plan: '{{ plan_info.stdout_lines[0] }}'
name: '{{ plan_info.stdout_lines[1] }}'
original_plan: '{{ plan_info.output[0] }}'
new_plan: '{{ plan_info.output[1] }}'

- 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 }}"
name: "{{ new_plan.name }}"
register: set_plan_check
check_mode: yes

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

Expand All @@ -28,29 +43,30 @@
assert:
that:
- set_plan_check is changed
- not set_plan_check_result.stdout_lines[0].endswith('*')
- set_plan_check_result.output[0].guid == original_plan.guid

#Test that setting plan and that change is applied
- name: set power plan
win_power_plan:
name: "{{ name }}"
name: "{{ new_plan.name }}"
register: set_plan

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

- name: assert setting plan
assert:
that:
- set_plan is changed
- set_plan_result.stdout_lines[0].endswith('*')
- set_plan_result.output[0].guid == new_plan.guid

#Test that plan doesn't apply change if it is already set
- name: set power plan (idempotent)
win_power_plan:
name: "{{ name }}"
name: "{{ new_plan.name }}"
register: set_plan_idempotent

- name: assert setting plan (idempotent)
Expand All @@ -61,29 +77,19 @@
always:
- name: always change back plan to the original when done testing
win_power_plan:
name: '{{ original_plan }}'

- name: get current plan guid details
ansible.windows.win_shell: |
$plan_info = powercfg.exe /list
($plan_info | Select-String -Pattern '([a-z0-9]+\-[a-z0-9]+\-[a-z0-9]+\-[a-z0-9]+\-[a-z0-9]+).+\*').Matches.Groups[1].Value
($plan_info | Select-String -Pattern '([a-z0-9]+\-[a-z0-9]+\-[a-z0-9]+\-[a-z0-9]+\-[a-z0-9]+)').Matches.Groups[1].Value
register: guid_plan_info

- set_fact:
original_plan: '{{ guid_plan_info.stdout_lines[0] }}'
name: '{{ guid_plan_info.stdout_lines[1] }}'
name: '{{ original_plan.name }}'

- block:
#Test that plan detects change is needed, but doesn't actually apply change
- name: set power plan guid (check mode)
win_power_plan:
guid: "{{ name }}"
guid: "{{ new_plan.guid }}"
register: set_plan_check_guid
check_mode: yes

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

Expand All @@ -92,29 +98,30 @@
assert:
that:
- set_plan_check_guid is changed
- not set_plan_check_result_guid.stdout_lines[0].endswith('*')
- set_plan_check_result_guid.output[0].guid == original_plan.guid

#Test that setting plan and that change is applied
- name: set power plan guid
win_power_plan:
guid: "{{ name }}"
guid: "{{ new_plan.guid }}"
register: set_plan_guid

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

- name: assert setting plan guid
assert:
that:
- set_plan_guid is changed
- set_plan_result_guid.stdout_lines[0].endswith('*')
- set_plan_result_guid.output[0].guid == new_plan.guid

#Test that plan doesn't apply change if it is already set
- name: set power plan guid (idempotent)
win_power_plan:
guid: "{{ name }}"
guid: "{{ new_plan.guid }}"
register: set_plan_idempotent_guid

- name: assert setting plan guid (idempotent)
Expand All @@ -125,4 +132,4 @@
always:
- name: always change back plan to the original when done testing guid
win_power_plan:
guid: '{{ original_plan }}'
guid: '{{ original_plan.guid }}'