Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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
like image 924
user6826691 Avatar asked Apr 26 '17 14:04

user6826691


People also ask

What is the ansible command to find the memory usage of your service?

Or you can also try running some shell command using grep/awk or something like cat /proc/meminfo or vmstat to get the memory usage on your servers and grab them in some file or something via output of ansible.

Which command allows you to see all the facts that ansible will gather about a machine?

Ansible stores facts in JSON format, with items grouped in nodes. To check what kind of information is available for the systems you're provisioning, you can run the setup module with an ad hoc command: ansible all -i inventory -m setup -u sammy.


1 Answers

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

like image 90
papey Avatar answered Sep 20 '22 07:09

papey