print free space for mount

17 views
Skip to first unread message

Nicholas Britton

unread,
May 1, 2019, 11:28:18 PM5/1/19
to Ansible Project
I am trying to print the free space for a mount that an application needs to have x free on.   Once i can do that i would look at adding actions based on that, but i would also like to the user running the play to know if there is an issue or not.   

Here is what i have so far, and i cant see to get what i would expect, any thoughts:

code:

---
- hosts: all

  tasks:
    - debug:
        msg: "Mount Point {{item.mount}} free space {{item.size_available/1073741824}} "
      loop: "{{ansible_mounts}}"
      when: item.mount == '/home'


output:
PLAY [all] **********************************************************************************************************************************************************

TASK [Gathering Facts] **********************************************************************************************************************************************
ok: [server]

TASK [debug] ********************************************************************************************************************************************************
skipping: [server] => (item={u'block_used': 3056865, u'uuid': u'bf9d7ab9-4be3-419d-8aed-f3b952b75957', u'size_total': 84408975360, u'block_total': 20607660, u'mount': u'/', u'block_available': 17550795, u'size_available': 71888056320, u'fstype': u'ext4', u'inode_total': 5242880, u'inode_available': 5165347, u'device': u'/dev/mapper/VolGroup-lv_root', u'inode_used': 77533, u'block_size': 4096, u'options': u'rw'})
skipping: [server] => (item={u'block_used': 109536, u'uuid': u'11dcc8c1-6895-4cc5-b6f3-6d83767021ac', u'size_total': 499355648, u'block_total': 487652, u'mount': u'/boot', u'block_available': 378116, u'size_available': 387190784, u'fstype': u'ext4', u'inode_total': 128016, u'inode_available': 127971, u'device': u'/dev/sda1', u'inode_used': 45, u'block_size': 1024, u'options': u'rw'})

ok: [server] => (item={u'block_used': 3071894, u'uuid': u'c6c79efc-1ada-4714-9d32-80a6cd896605', u'size_total': 105558474752, u'block_total': 25771112, u'mount': u'/home', u'block_available': 22699218, u'size_available': 92975996928, u'fstype': u'ext4', u'inode_total': 6540800, u'inode_available': 6382890, u'device': u'/dev/mapper/VolGroup-lv_home', u'inode_used': 157910, u'block_size': 4096, u'options': u'rw'}) => {
    "msg": "Mount Point /home free space 86.5906448364 "
}

What i really want to display and only display is : "Mount Point /home free space 86.5906448364 "

Kai Stian Olstad

unread,
May 8, 2019, 3:19:10 PM5/8/19
to ansible...@googlegroups.com
Then you would need to write you own callback plugin or try the included ones to see if have output you like
https://docs.ansible.com/ansible/latest/plugins/callback.html


--
Kai Stian Olstad
Reply all
Reply to author
Forward
0 new messages