Last active
August 1, 2023 20:50
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- 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