diff --git a/www-windows-check-free-disk-space.yaml b/www-windows-check-free-disk-space.yaml index 1b1c4b4..562196b 100644 --- a/www-windows-check-free-disk-space.yaml +++ b/www-windows-check-free-disk-space.yaml @@ -20,20 +20,28 @@ when: - freediskspace.stdout | trim | float < 20 - - name: Find Recovery partitions and sizes (MB) + - name: Find Recovery partitions (PowerShell → JSON) ansible.windows.win_powershell: - script: | - $guid = '{DE94BBA4-06D1-4D40-A16A-BFD50179D6AC}' - $parts = Get-Partition | - Where-Object { - $_.GptType -eq $guid -or $_.Type -eq 'Recovery' -or $_.Type -eq 'Unknown' - } | - Select-Object DiskNumber, PartitionNumber, - @{n='SizeMB';e={[math]::Round($_.Size/1MB,2)}}, - GptType, Type - $parts | ConvertTo-Json -Compress - register: winre_parts + script: | + $guid = '{DE94BBA4-06D1-4D40-A16A-BFD50179D6AC}' + $parts = @( Get-Partition | + Where-Object { $_.GptType -eq $guid -or $_.Type -eq 'Recovery' -or $_.Type -eq 'Unknown' } | + Select-Object DiskNumber, PartitionNumber, + @{n='SizeBytes';e={$_.Size}}, + @{n='SizeMB';e={[math]::Round($_.Size/1MB,2)}}, + GptType, Type ) + $parts | ConvertTo-Json -Compress -Depth 4 + register: winre_raw + changed_when: false - - name: Show results + - name: Parse JSON to a list + ansible.builtin.set_fact: + winre_parts: >- + {{ (winre_raw.output | join('') | trim) | default('[]') | from_json }} + + - name: Show Recovery partition sizes ansible.builtin.debug: - var: winre_parts.output | from_json \ No newline at end of file + msg: >- + Disk {{ item.DiskNumber }}, Partition {{ item.PartitionNumber }}, + Size: {{ item.SizeMB }} MB ({{ item.SizeBytes }} bytes) + loop: "{{ winre_parts }}" \ No newline at end of file