39 lines
1.4 KiB
YAML
39 lines
1.4 KiB
YAML
---
|
|
- name: Check Free Disk Space
|
|
hosts: windows
|
|
gather_facts: false
|
|
tasks:
|
|
- name: "Check Free Disk Space in C:"
|
|
win_shell: |
|
|
$freeSpace = [math]::Round((Get-PSDrive C | Select-Object Free).Free / 1GB, 2)
|
|
Write-Output $freeSpace
|
|
register: freediskspace
|
|
|
|
- name: Report Free Disk Space
|
|
debug:
|
|
msg: "Free disk space on C: drive: {{ freediskspace.stdout | trim }} GB"
|
|
when: freediskspace is defined and freediskspace.stdout is defined
|
|
|
|
- name: Fail if there is not Enough Space
|
|
fail:
|
|
msg: "the node {{ inventory_hostname }} has insufficient disk space: {{ freediskspace.stdout | trim }} GB (minimum required: 20 GB)"
|
|
when:
|
|
- freediskspace.stdout | trim | float < 20
|
|
|
|
- name: Find Recovery partitions and sizes (MB)
|
|
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
|
|
|
|
- name: Show results
|
|
ansible.builtin.debug:
|
|
var: winre_parts.output | from_json |