Ansible Playbooks

Check Diskspace

Welcome

This playbook checks the disk space usage of the root filesystem (/) on the specified hosts, extracts the percentage of disk space used, and stores this information in the variable disk_usage. The task does not alter the system state and is designed to run in any mode.

Please be aware, the coding on this site is meant to guide. Testing these scripts in a non-production environment is strongly encouraged. I take no responsibility for use of any scripts on this site or on my github repositories.


Playbook:

---
- name: Check disk space
  hosts: "{{ my_hosts | d([]) }}"

  tasks:
    - name: Check disk space available
      ansible.builtin.shell:
        cmd: |
          set -euo pipefail
          df -Ph / | awk 'NR==2 {print $5}'
        executable: /bin/bash
      changed_when: false
      check_mode: false
      register: disk_usage

View on GitHub