Merge pull request 'aggiunta cron job che fa il prune di volumi giornalmente' (!3) from marco.procaccini/ansible-role-docker:master into master

Reviewed-on: #3
This commit is contained in:
Andrea Dell'Amico 2025-07-05 12:16:44 +02:00
commit 1914e6e9c5
4 changed files with 43 additions and 2 deletions

View File

@ -62,3 +62,4 @@ docker_node_labels: []
# - { key: 'key_name', value: 'label_value' }
docker_restart_daemon_cronjob: false
docker_prune_dangling_volumes: false

View File

@ -1,5 +1,5 @@
#!/usr/bin/env bash
# "system" prune, because pruning images only leaves a lot of garbage around
docker system prune --force > /var/log/docker-prune.log 2>&1
docker volume prune --force > /var/log/docker-volume-prune.log 2>&1
exit 0

View File

@ -0,0 +1,5 @@
#!/usr/bin/env bash
# "system" prune, because pruning images only leaves a lot of garbage around
docker system prune --force > /var/log/docker-prune.log 2>&1
exit 0

View File

@ -106,6 +106,41 @@
when: docker_install
tags: [docker, docker_restart_daemon_cronjob]
- name: Cron job that prunes the dangling volumes
block:
- name: 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: Install a cron job that prunes the docker volumes
cron:
name: Prune docker volumes
cron_file: docker-prune-volumes
special_time: daily
user: root
state: present
job: "/usr/local/sbin/docker-prune-dangling-volumes"
when: docker_prune_dangling_volumes
- name: Disable the cron job that prunes the docker volumes
cron:
name: Prune docker volumes
cron_file: docker-prune-volumes
special_time: daily
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]
- block:
- name: Remove the docker user
user: name=docker state=absent