---
- name: This playbook is for Testing Disk Space
hosts: proxy
become: yes
become_method: sudo
serial: 1
any_errors_fatal: true
ignore_errors: yes
gather_facts: yes
vars:
ansible_paython_interpreter: /usr/bin/python
tasks:
- name: disk usage from command module
shell: df -h / | tail -n 1 | awk '{ print $5 }'
register: used_space
- debug:
var: used_space.stdout
- name: update the system
yum:
name: "*"
state: latest
exclude: 'kernel*'
update_cache: yes
update_only: yes
when: ansible_os_family == 'RedHat' and used_space < '70%'
failed_when: used_space >= '70%'
register: yum_update
- debug:
msg: "{{ yum_update }}"
``
Help me if their is other way to do my task . I want to check the disk space and if space is not used more then 70% then continue to update or else fail the play and exit and send email that only this much space left.