Skip to content

Instantly share code, notes, and snippets.

@goodc0re
Created July 14, 2019 04:32
Show Gist options
  • Save goodc0re/cbaffab5674cc9324ecb591ab350e564 to your computer and use it in GitHub Desktop.
Save goodc0re/cbaffab5674cc9324ecb591ab350e564 to your computer and use it in GitHub Desktop.
Ansible playbook that checks if there is less than 95% free disk space
# checkdiskspaceall.yml
---
- hosts: zcoin_masternodes
vars_files: vault.yml
become: yes
become_method: sudo
gather_facts: yes
tasks:
- name: Collect only facts about hardware
setup:
gather_subset:
- 'hardware'
- name: Test for available disk space
setup: filter=ansible_mounts
- name: Ensure that free space on the tested volume is greater than 15%
assert:
that:
- mount.size_available > mount.size_total|float * 0.05
msg: Disk space has reached 95% threshold
vars:
mount: "{{ ansible_mounts | selectattr('mount','equalto',item.mount) | list | first }}"
with_items:
- "{{ ansible_mounts }}"
@goodc0re
Copy link
Author

goodc0re commented Jul 14, 2019

This playbook requires:

  • ssh keys uploaded to the hosts for ansible to log in
  • ansible to be installed on the controlling machine (can be your local machine or another server)
  • a hosts file on the controlling machine that specifies the IP addresses, ssh ports and login usernames of the hosts / nodes
  • an ansible vault file on the controlling machine with the encrypted passwords that are needed for sudo

Command I use to run this playbook with ansible:

$ sudo ansible-playbook -i hosts --ask-vault-pass checkdiskspaceall.ylm -vv

@aligolestan
Copy link

how can I check only / partition ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment