updated cronjob that prune the docker system

This commit is contained in:
Marco Procaccini 2026-02-02 13:58:08 +01:00
parent 012292c6fd
commit 46165cfdc4
4 changed files with 18 additions and 69 deletions

View File

@ -66,5 +66,6 @@ docker_label_state_mode: merge
docker_node_labels: [] docker_node_labels: []
# - { key: 'key_name', value: 'label_value' } # - { key: 'key_name', value: 'label_value' }
docker_restart_daemon_cronjob: false docker_restart_daemon_cronjob: false
docker_prune_dangling_volumes: false docker_system_prune_all: true

View File

@ -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

View File

@ -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

View File

@ -69,38 +69,38 @@
- Restart containerd - Restart containerd
- Restart docker - Restart docker
- name: docker_setup | Cron job that prunes the dangling images - name: Cron job that prunes all the docker system
block: block:
- name: docker_setup | Install a script that prunes the docker dangling images - name: Install a script that prunes the entire docker system
copy: copy:
src: docker-prune-dangling-images.sh src: docker-system-prune-all.sh
dest: /usr/local/sbin/docker-prune-dangling-images dest: /usr/local/sbin/docker-system-prune-all
owner: root owner: root
group: 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: cron:
name: Prune docker images name: Prune docker system
cron_file: docker-prune-images cron_file: docker-system-prune-all
special_time: daily special_time: daily
user: root user: root
state: present state: present
job: "/usr/local/sbin/docker-prune-dangling-images" job: "/usr/local/sbin/docker-system-prune-all"
when: docker_prune_dangling_images 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: cron:
name: Prune docker images name: Prune docker system
cron_file: docker-prune-images cron_file: docker-system-prune-all
special_time: daily special_time: daily
user: root user: root
state: absent state: absent
job: "/usr/local/sbin/docker-prune-dangling-images" job: "/usr/local/sbin/docker-system-prune-all"
when: not docker_prune_dangling_images when: not docker_system_prune_all
when: docker_install when: docker_install
tags: [docker, docker_prune_images] tags: [docker, docker_system_prune_all]
- name: docker_setup | Cron job that restart docker daemon daily - name: docker_setup | Cron job that restart docker daemon daily
block: block:
@ -137,37 +137,3 @@
when: docker_install when: docker_install
tags: [docker, docker_restart_daemon_cronjob] 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]