Skip to content

Instantly share code, notes, and snippets.

@victorbrca
Last active August 1, 2023 20:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save victorbrca/8e8af69db44b64e9df5ffaf55b4b6dae to your computer and use it in GitHub Desktop.
Save victorbrca/8e8af69db44b64e9df5ffaf55b4b6dae to your computer and use it in GitHub Desktop.
Purges YUM cache to free disk space when var is over 55% utilization
---
- name: Delete yum cache and run yum check-update
# Add your hosts accordingly below
hosts: webserver
become: yes
tasks:
- name: Check /var usage with df command
shell: |
df -hT /var | awk '{print $6}' | tail -1 | tr -d '%'
register: var_usage_output
- name: Display /var usage information
debug:
var: var_usage_output.stdout
##-- Block starts --------------------------------------------------------------
- when: var_usage_output.stdout|int > 55
block:
- name: Delete yum cache directory
file:
path: /var/cache/yum
state: absent
- name: Update YUM cache
yum:
name: ''
update_cache: yes
- name: Check /var usage with df command
shell: |
df -hT /var | awk '{print $6}' | tail -1
register: var_usage_after_cleanup_output
- name: Display /var usage information
debug:
var: var_usage_after_cleanup_output.stdout
##-- block ends ----------------------------------------------------------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment