docker: hourly prune of objects older than 7 days, root mail only when the prune fails

This commit is contained in:
2026-10-26 10:18:29 +00:00
parent d61403ee33
commit fee8ec1ff6
2 changed files with 38 additions and 0 deletions
+12
View File
@@ -0,0 +1,12 @@
#!/bin/bash
# Silent on success: cron mails all output to root, so mail arrives only when the prune fails.
set -u
output=$(docker system prune -af --filter "until=168h" 2>&1)
rc=$?
if [ "$rc" -ne 0 ]; then
printf '%s\n' "$output"
echo "docker system prune exited with rc=$rc"
exit "$rc"
fi
+26
View File
@@ -65,3 +65,29 @@
dest: "/usr/local/bin/docker-compose" dest: "/usr/local/bin/docker-compose"
mode: preserve mode: preserve
- name: Check for docker binary
ansible.builtin.stat:
path: /usr/bin/docker
register: docker_binary
tags: docker_prune
- name: Deploy docker-prune script
ansible.builtin.copy:
src: docker-prune
dest: /usr/local/sbin/docker-prune
owner: root
group: root
mode: "0755"
when: docker_binary.stat.exists
tags: docker_prune
- name: Schedule hourly docker-prune
ansible.builtin.cron:
name: docker prune
cron_file: docker-prune
user: root
minute: "0"
job: /usr/local/sbin/docker-prune
when: docker_binary.stat.exists
tags: docker_prune