39 lines
1.3 KiB
YAML
39 lines
1.3 KiB
YAML
---
|
|
- name: "Debug | Disk usage"
|
|
hosts: all
|
|
gather_facts: true
|
|
|
|
tasks:
|
|
- name: "Linux | Collect filesystem usage"
|
|
when: ansible_facts['os_family'] != 'Windows'
|
|
ansible.builtin.command:
|
|
cmd: df -hP -x tmpfs -x devtmpfs
|
|
register: disk_usage_linux
|
|
changed_when: false
|
|
|
|
- name: "Linux | Show filesystem usage"
|
|
when: ansible_facts['os_family'] != 'Windows'
|
|
ansible.builtin.debug:
|
|
var: disk_usage_linux.stdout_lines
|
|
|
|
- name: "Windows | Collect filesystem drive usage"
|
|
when: ansible_facts['os_family'] == 'Windows'
|
|
ansible.windows.win_powershell:
|
|
script: |
|
|
Get-CimInstance Win32_LogicalDisk -Filter "DriveType=3" |
|
|
Select-Object DeviceID,
|
|
@{Name='SizeGB';Expression={[math]::Round($_.Size / 1GB, 2)}},
|
|
@{Name='FreeGB';Expression={[math]::Round($_.FreeSpace / 1GB, 2)}},
|
|
@{Name='UsedPercent';Expression={
|
|
if ($_.Size -gt 0) {
|
|
[math]::Round((($_.Size - $_.FreeSpace) / $_.Size) * 100, 1)
|
|
} else { 0 }
|
|
}}
|
|
register: disk_usage_windows
|
|
changed_when: false
|
|
|
|
- name: "Windows | Show filesystem drive usage"
|
|
when: ansible_facts['os_family'] == 'Windows'
|
|
ansible.builtin.debug:
|
|
var: disk_usage_windows.output
|