Here is a snippet I use to quickly check an inventory of hosts in ansible on how much disk space they have remaining / visually alert me to see if any hosts are for example exceeding >90 % usage for the root mount and ignore other mounts.
You can modify this variable to alert you based on what % filled the root mount is
usage_threshold_percent: 90
---
- name: Check root filesystem usage
hosts: all
user: root
gather_facts: true
vars:
usage_threshold_percent: 90
tasks:
- name: Locate root mount info
set_fact:
root_mount: "{{ ansible_facts.mounts | selectattr('mount', '==', '/') | list | first }}"
when: ansible_facts.mounts is defined
- name: Compute root filesystem used percent
set_fact:
root_used_percent: "{{ (100 - ((root_mount.size_available | float) / (root_mount.size_total | float) * 100)) | round(2) }}"
when:
- root_mount is defined
- root_mount.size_total is defined
- (root_mount.size_total | float) > 0
- name: Report high root filesystem usage
debug:
msg: "Host {{ inventory_hostname }}: / is at {{ root_used_percent }}% used (>= {{ usage_threshold_percent }}%)"
when:
- root_used_percent is defined
- (root_used_percent | float) >= (usage_threshold_percent | float)
output will look like this (assuming the host has more than 10% available disk space
skipping: [24-trello]
skipping: [24-spotted]
skipping: [24-calculator]
skipping: [24-post-silver]
skipping: [24-post-jealous]
skipping: [24-post-lazy]
skipping: [24-post-lollypop]
skipping: [24-post-museum]
skipping: [24-post-sirius]
skipping: [24-bollywood]
skipping: [24-happyhippo]
skipping: [24-stop122]
skipping: [24-marketlane]
skipping: [24-smiling-child]
skipping: [24-bst]
skipping: [24-kinopio]
skipping: [24-sanga]
skipping: [24-diagram]
skipping: [24-emporium]
skipping: [24-englishbreakfast]
skipping: [24-cocacola]