Ansible - How to check the physical memory and free disk is greater than some value?

user6826691 picture user6826691 · Apr 26, 2017 · Viewed 21.6k times · Source

How to write an ansible task to check if the physical memory >=128 MB and free disk is >= 256 MB. i tried to get the output but i am not sure how to proceed further.

# Check the physical disk memory 128 MB and free disk 256 MB
 - name: check the physical memory
   command: vmstat -s
   register: phy_mem

Answer

papey picture papey · Apr 26, 2017

When you start a playbook, Ansible first task is always

TASK [Gathering Facts] 

This tasks fetch some internal variables used by Ansible but usable inside your playbook.

For example for a memory check look at variable ansible_memory_mb.real.total

- assert:
    that:
        - ansible_memtotal_mb >= 128

Now you want a list of all the internal variables :

ansible -m setup hostname

Here is the complete list Ansible and hardware checks (names and stuff may changed between old and new Ansible release)

Source : http://docs.ansible.com/ansible/setup_module.html