11

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
user6826691
  • 1,813
  • 9
  • 37
  • 74

1 Answers1

17

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)

Version 2.3 Source : https://docs.ansible.com/ansible/2.3/setup_module.html
Current Source : https://docs.ansible.com/ansible/latest/user_guide/playbooks_vars_facts.html

Christopher Chase
  • 2,840
  • 6
  • 36
  • 57
papey
  • 3,854
  • 1
  • 19
  • 18
  • 4
    This answers just half of the question. But [this](http://stackoverflow.com/q/26981907/402322) may answer the other part. – ceving Apr 26 '17 at 14:57
  • @Swat - Please open a new question and post in your Ansible YAML code that is showing this error. I suspect you might need to add a "gather_facts: True" line to the YAML, or possibly change your test to "- ansible_memfree_mb|int >= 256" (note the inclusion of the "|int" cast). – dan_linder Apr 27 '17 at 12:59