Add cron job to prune unused Docker data

This commit is contained in:
Sam A. 2023-07-07 23:15:05 +02:00
parent d3af3b9e28
commit ca73aa5b9b
Signed by: samsapti
GPG key ID: CBBBE7371E81C4EA
3 changed files with 12 additions and 1 deletions

View file

@ -7,6 +7,7 @@ usage() {
printf '$ %s\n' "$0 [-h|--help]" printf '$ %s\n' "$0 [-h|--help]"
printf '$ %s\n' "$0 [--dry] os" printf '$ %s\n' "$0 [--dry] os"
printf '$ %s\n' "$0 [--dry] docker" printf '$ %s\n' "$0 [--dry] docker"
printf '$ %s\n' "$0 [--dry] docker_config"
printf '$ %s\n' "$0 [--dry] firewall" printf '$ %s\n' "$0 [--dry] firewall"
printf '$ %s\n' "$0 [--dry] ssh" printf '$ %s\n' "$0 [--dry] ssh"
printf '$ %s\n' "$0 [--dry] users [-i|--init]" printf '$ %s\n' "$0 [--dry] users [-i|--init]"
@ -38,7 +39,7 @@ fi
case $TAG in case $TAG in
"") "")
install_modules; $EXEC "$BASE_CMD" ;; install_modules; $EXEC "$BASE_CMD" ;;
os|docker|firewall|ssh) os|docker|docker_config|firewall|ssh)
install_modules; $EXEC "$BASE_CMD --tags '$TAG'" ;; install_modules; $EXEC "$BASE_CMD --tags '$TAG'" ;;
users) users)
install_modules install_modules

View file

@ -17,3 +17,12 @@
- docker.socket - docker.socket
- docker.service - docker.service
when: stop is undefined or not stop when: stop is undefined or not stop
- name: Configure cron job to prune unused Docker data weekly
ansible.builtin.cron:
name: Prune unused Docker data
cron_file: ansible_docker_prune
job: 'docker system prune -fa && docker volume prune -fa'
special_time: weekly
user: root
state: present

View file

@ -40,6 +40,7 @@
- name: Configure Docker - name: Configure Docker
ansible.builtin.import_tasks: config.yml ansible.builtin.import_tasks: config.yml
tags: tags:
- docker_config
- reboot - reboot
- name: Set up Docker services - name: Set up Docker services