Ansible - df module (disk filesystem usage ansible_mounts)

Ansible does not have a "df" module to capture the output of the df command. Instead, facts can be used to capture the df output.

Let's say the df command on server1 returns the following.

[john.doe@server1 ~]# df
Filesystem                           1K-blocks     Used Available Use% Mounted on
/dev/sda1                               372607   170989    177862  50% /boot
/dev/sda2                               129774     6994    122780   6% /


Here is how you can get the df output using facts.

- hosts: all
  - name: display ansible_mounts
      var: ansible_mounts


Something like this should be returned. Notice here that size_available and size_total are in bytes, not kilobytes (KB).

TASK [display ansible_mounts]
ok: [localhost] => {
    "ansible_mounts": [
            "block_available": 9162312, 
            "block_size": 4096, 
            "block_total": 9170560, 
            "block_used": 8248, 
            "device": "/dev/sda1", 
            "fstype": "xfs", 
            "inode_available": 18350077, 
            "inode_total": 18350080, 
            "inode_used": 3, 
            "mount": "/boot", 
            "options": "", 
            "size_available": 182130688, 
            "size_total": 381549568, 
            "uuid": "5629a4fd-3e07-4bfa-a4f7-5b2cccfd6e6e"
            "block_available": 9207314, 
            "block_size": 65536, 
            "block_total": 13578240, 
            "block_used": 4370926, 
            "device": "/dev/sda2", 
            "fstype": "xfs", 
            "inode_available": 20597477, 
            "inode_total": 21251126, 
            "inode_used": 653649, 
            "mount": "/", 
            "options": "", 
            "size_available": 125726720, 
            "size_total": 132888576, 
            "uuid": "N/A"


Almost always, there are multiple mounts, which means you'll have to use the loop, with_items or with_list parameters to loop through each item in the ansible_mounts array.

- hosts: all
  - name: loop through each ansible_mounts
      msg: "{{ item }}"
    with_items: "{{ ansible_mounts }}"


Add a Comment

We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.

Please enter 32d58 in the box below so that we can be sure you are a human.


Web design by yours truely - me, myself, and I   |   |