init commit
This commit is contained in:
46
playbooks/check_unallocated_disk.yml
Normal file
46
playbooks/check_unallocated_disk.yml
Normal file
@@ -0,0 +1,46 @@
|
||||
---
|
||||
- name: Check unallocated disk space
|
||||
hosts: all
|
||||
become: true
|
||||
gather_facts: false
|
||||
|
||||
tasks:
|
||||
|
||||
- name: Get block device sizes
|
||||
command: lsblk -b -o NAME,SIZE,TYPE -dn
|
||||
register: lsblk_output
|
||||
|
||||
- name: Parse lsblk output into structured facts
|
||||
set_fact:
|
||||
disks: "{{ disks | default({}) | combine({ item.split()[0]: item.split()[1]|int }) }}"
|
||||
loop: "{{ lsblk_output.stdout_lines }}"
|
||||
when: "'disk' in item"
|
||||
|
||||
- name: Get partition sizes for each disk
|
||||
command: lsblk -b -o NAME,SIZE,TYPE -n
|
||||
register: partition_output
|
||||
|
||||
- name: Initialize disk usage map
|
||||
set_fact:
|
||||
used_space: "{{ used_space | default({}) }}"
|
||||
|
||||
- name: Sum partition sizes under each disk
|
||||
set_fact:
|
||||
used_space: >-
|
||||
{{
|
||||
used_space | combine({
|
||||
(item.0): (used_space[item.0]|default(0)) + (item.1.split()[1]|int)
|
||||
})
|
||||
}}
|
||||
with_nested:
|
||||
- "{{ disks.keys() | list }}"
|
||||
- "{{ partition_output.stdout_lines }}"
|
||||
when: item.1.startswith(item.0) and 'part' in item.1
|
||||
|
||||
- name: Show disk usage summary
|
||||
debug:
|
||||
msg: >-
|
||||
Disk /dev/{{ item.key }}: Total {{ item.value|int // 1024**3 }} GB,
|
||||
Used {{ used_space[item.key]|default(0)|int // 1024**3 }} GB,
|
||||
Unallocated {{ (item.value|int - used_space[item.key]|default(0)|int) // 1024**3 }} GB
|
||||
loop: "{{ disks|dict2items }}"
|
Reference in New Issue
Block a user