Checking for a full(ish) disks with Ansible

While Ansible is great for deployment and configuration purposes, it can also be an amazing operational tool.

One common task in an environment is to check for full, or nearly full, file systems. With this Ansible one-liner you can query all systems in an environment and print an Alert for a given node stating exactly how much storage is being used and on which device/partition.

Example command using 90% as the threshold.

ansible -m shell -a "df -h | tail -n +2 | sed s/%//g | awk '{ if(\$5 > 90) print \"Alert \"\$0;}'" all --forks 100

Here is what a run would look like. Note using 1% as the threshold.

ansible -m shell -a "df -h | tail -n +2 | sed s/%//g | awk '{ if(\$5 > 1) print \"Alert \"\$0;}'" all --limit 727404-object-disk-034
727404-object-disk-034 | success | rc=0 >>
Alert /dev/mapper/lxc-root00        40G  5.1G   35G  13 /
Alert /dev/sda2                    976M   43M  918M   5 /boot

In my example I'm using the all group which is an Ansible built in, but if you want to limit the scope of your command simply change "all" to an appropriate group name based on your inventory.

Mastodon