From c1c18a628c3aab593b234d97c1fbe9400c043754 Mon Sep 17 00:00:00 2001 From: Sam Al-Sapti Date: Fri, 7 Jul 2023 23:19:07 +0200 Subject: [PATCH] Add cron job to prune unused Docker data --- roles/docker_services/tasks/config.yml | 10 ++++++++-- roles/docker_services/tasks/main.yml | 7 ++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/roles/docker_services/tasks/config.yml b/roles/docker_services/tasks/config.yml index 7da021c..39bcff0 100644 --- a/roles/docker_services/tasks/config.yml +++ b/roles/docker_services/tasks/config.yml @@ -8,5 +8,11 @@ mode: u=rw,g=r,o=r notify: reload-dockerd -- name: Flush handlers - ansible.builtin.meta: flush_handlers +- name: Configure cron job to prune unused Docker data weekly + ansible.builtin.cron: + name: Prune unused Docker data + cron_file: ansible_docker_prune + job: 'docker system prune -fa && docker volume prune -fa' + special_time: weekly + user: root + state: present diff --git a/roles/docker_services/tasks/main.yml b/roles/docker_services/tasks/main.yml index ac7b858..4dffa87 100644 --- a/roles/docker_services/tasks/main.yml +++ b/roles/docker_services/tasks/main.yml @@ -8,7 +8,7 @@ - name: Add Docker apt repository ansible.builtin.apt_repository: - repo: deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian bullseye stable + repo: 'deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian bullseye stable' state: present update_cache: true @@ -39,6 +39,11 @@ - name: Configure Docker ansible.builtin.import_tasks: config.yml + tags: + - docker_config + +- name: Flush handlers + ansible.builtin.meta: flush_handlers - name: Set up Docker services ansible.builtin.import_tasks: services.yml