Prune the dangling images daily.

This commit is contained in:
Andrea Dell'Amico 2022-05-21 19:45:46 +02:00
parent 593d02c6e2
commit 2eae7c68db
Signed by: adellam
GPG Key ID: 147ABE6CEB9E20FF
3 changed files with 39 additions and 0 deletions

View File

@ -12,6 +12,8 @@ docker_swarm_worker_hostname: '{{ ansible_fqdn }}'
docker_swarm_allowed_hosts: docker_swarm_allowed_hosts:
- '0.0.0.0/0' - '0.0.0.0/0'
docker_prune_dangling_images: true
# Set this to one of the manager hostnames to be able to initialize the cluster # Set this to one of the manager hostnames to be able to initialize the cluster
docker_swarm_manager_main_node_hostname: localhost docker_swarm_manager_main_node_hostname: localhost
docker_swarm_manager_main_node_address: 127.0.0.1 docker_swarm_manager_main_node_address: 127.0.0.1

View File

@ -0,0 +1,4 @@
#!/usr/bin/env bash
docker image prune --force > /var/log/docker-prune.log 2>&1
exit 0

View File

@ -40,6 +40,39 @@
when: docker_install when: docker_install
tags: [docker] tags: [docker]
- name: Cron job that prunes the dangling images
block:
- name: Install a script that prunes the docker dangling images
copy:
src: docker-prune-dangling-images.sh
dest: /usr/local/sbin/docker-prune-dangling-images
owner: root
group: root
mode: 0744
- name: Install a cron job that prunes the docker images
cron:
name: Prune docker images
cron_file: docker-prune-images
special_time: daily
user: root
state: present
job: "/usr/local/sbin/docker-prune-dangling-images"
when: docker_prune_dangling_images
- name: Disable the cron job that prunes the docker images
cron:
name: Prune docker images
cron_file: docker-prune-images
special_time: daily
user: root
state: absent
job: "/usr/local/sbin/docker-prune-dangling-images"
when: not docker_prune_dangling_images
when: docker_install
tags: [docker, docker_prune_images]
- block: - block:
- name: Remove the docker user - name: Remove the docker user
user: name=docker state=absent user: name=docker state=absent