45 lines
1.6 KiB
YAML
45 lines
1.6 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: Gather disk & partition facts
|
|
community.windows.win_disk_facts:
|
|
|
|
- name: Show Recovery partition sizes (handles GPT + MBR)
|
|
ansible.builtin.debug:
|
|
msg: >-
|
|
Recovery partition (part {{ item.number|default('n/a') }}, offset {{ item.offset }})
|
|
size: {{ item.size | filesizeformat }}
|
|
loop: >-
|
|
{{
|
|
(
|
|
ansible_facts.disks | map(attribute='partitions') | list | flatten
|
|
| selectattr('gpt_type','defined')
|
|
| selectattr('gpt_type','search','(?i)de94bba4-06d1-4d40-a16a-bfd50179d6ac')
|
|
)
|
|
+
|
|
(
|
|
ansible_facts.disks | map(attribute='partitions') | list | flatten
|
|
| selectattr('mbr_type','defined')
|
|
| selectattr('mbr_type','equalto',27)
|
|
)
|
|
}}
|