From 46165cfdc4a7cf913af30a65d5dca004865417b5 Mon Sep 17 00:00:00 2001 From: Marco Procaccini Date: Mon, 2 Feb 2026 13:58:08 +0100 Subject: [PATCH] updated cronjob that prune the docker system --- defaults/main.yml | 3 +- files/docker-prune-dangling-images.sh | 9 ---- files/docker-prune-dangling-volumes.sh | 9 ---- tasks/docker_setup.yml | 66 +++++++------------------- 4 files changed, 18 insertions(+), 69 deletions(-) delete mode 100644 files/docker-prune-dangling-images.sh delete mode 100644 files/docker-prune-dangling-volumes.sh diff --git a/defaults/main.yml b/defaults/main.yml index 7efa6de..0f360ce 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -66,5 +66,6 @@ docker_label_state_mode: merge docker_node_labels: [] # - { key: 'key_name', value: 'label_value' } + docker_restart_daemon_cronjob: false -docker_prune_dangling_volumes: false +docker_system_prune_all: true diff --git a/files/docker-prune-dangling-images.sh b/files/docker-prune-dangling-images.sh deleted file mode 100644 index d25ae12..0000000 --- a/files/docker-prune-dangling-images.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/env bash - -LOG_FILE="/var/log/docker-system-prune.log" -echo "===== $(date '+%Y-%m-%d %H:%M:%S') =====" >> "$LOG_FILE" -# "system" prune, because pruning images only leaves a lot of garbage around -docker system prune --force >> "$LOG_FILE" 2>&1 - -echo "" >> "$LOG_FILE" -exit 0 diff --git a/files/docker-prune-dangling-volumes.sh b/files/docker-prune-dangling-volumes.sh deleted file mode 100644 index 28f6759..0000000 --- a/files/docker-prune-dangling-volumes.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/env bash - -LOG_FILE="/var/log/docker-volumes-prune.log" -echo "===== $(date '+%Y-%m-%d %H:%M:%S') =====" >> "$LOG_FILE" -# "system" prune, because pruning images only leaves a lot of garbage around -docker volume prune --force >> "$LOG_FILE" 2>&1 - -echo "" >> "$LOG_FILE" -exit 0 diff --git a/tasks/docker_setup.yml b/tasks/docker_setup.yml index 4060859..95e0baa 100644 --- a/tasks/docker_setup.yml +++ b/tasks/docker_setup.yml @@ -69,38 +69,38 @@ - Restart containerd - Restart docker -- name: docker_setup | Cron job that prunes the dangling images +- name: Cron job that prunes all the docker system block: - - name: docker_setup | Install a script that prunes the docker dangling images + - name: Install a script that prunes the entire docker system copy: - src: docker-prune-dangling-images.sh - dest: /usr/local/sbin/docker-prune-dangling-images + src: docker-system-prune-all.sh + dest: /usr/local/sbin/docker-system-prune-all owner: root group: root - mode: "0744" + mode: 0744 - - name: docker_setup | Install a cron job that prunes the docker images + - name: Install a cron job that prunes the entire docker system cron: - name: Prune docker images - cron_file: docker-prune-images + name: Prune docker system + cron_file: docker-system-prune-all special_time: daily user: root state: present - job: "/usr/local/sbin/docker-prune-dangling-images" - when: docker_prune_dangling_images + job: "/usr/local/sbin/docker-system-prune-all" + when: docker_system_prune_all - - name: docker_setup | Disable the cron job that prunes the docker images + - name: Disable the cron job that prunes the docker system cron: - name: Prune docker images - cron_file: docker-prune-images + name: Prune docker system + cron_file: docker-system-prune-all special_time: daily user: root state: absent - job: "/usr/local/sbin/docker-prune-dangling-images" - when: not docker_prune_dangling_images + job: "/usr/local/sbin/docker-system-prune-all" + when: not docker_system_prune_all when: docker_install - tags: [docker, docker_prune_images] + tags: [docker, docker_system_prune_all] - name: docker_setup | Cron job that restart docker daemon daily block: @@ -137,37 +137,3 @@ when: docker_install tags: [docker, docker_restart_daemon_cronjob] -- name: docker_setup | Cron job that prunes the dangling volumes - block: - - name: docker_setup | Install a script that prunes the docker dangling volumes - copy: - src: docker-prune-dangling-volumes.sh - dest: /usr/local/sbin/docker-prune-dangling-volumes - owner: root - group: root - mode: "0744" - - - name: docker_setup | Install a cron job that prunes the docker volumes - cron: - name: Prune docker volumes - cron_file: docker-prune-volumes - minute: "0" - hour: "*/12" - user: root - state: present - job: "/usr/local/sbin/docker-prune-dangling-volumes" - when: docker_prune_dangling_volumes - - - name: docker_setup | Disable the cron job that prunes the docker volumes - cron: - name: Prune docker volumes - cron_file: docker-prune-volumes - minute: "0" - hour: "*/12" - user: root - state: absent - job: "/usr/local/sbin/docker-prune-dangling-volumes" - when: not docker_prune_dangling_volumes - - when: docker_install - tags: [docker, docker_prune_volumes]