From 3460fe3302c1c3d5f1dec3f7c74ce0490baea04e Mon Sep 17 00:00:00 2001 From: gabriel becker Date: Sat, 16 Aug 2025 21:47:37 +1000 Subject: [PATCH] Make docker install more reliable --- requirements.yml | 4 ++-- roles/webserver/tasks/install_docker.yml | 9 +++++++++ roles/webserver/tasks/start_service.yml | 11 +++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/requirements.yml b/requirements.yml index e65176c..3126e6c 100644 --- a/requirements.yml +++ b/requirements.yml @@ -1,3 +1,3 @@ --- -roles: - - name: community.docker.docker_compose \ No newline at end of file +collections: +- name: community.docker diff --git a/roles/webserver/tasks/install_docker.yml b/roles/webserver/tasks/install_docker.yml index 819ba89..8e41a8d 100644 --- a/roles/webserver/tasks/install_docker.yml +++ b/roles/webserver/tasks/install_docker.yml @@ -66,3 +66,12 @@ name: docker-compose-plugin state: latest update_cache: true + + - name: Create daily Docker system prune cron job + ansible.builtin.cron: + name: "Daily Docker system prune" + minute: "0" + hour: "3" + job: "docker system prune -f --all" + user: root + state: present diff --git a/roles/webserver/tasks/start_service.yml b/roles/webserver/tasks/start_service.yml index 62da8e1..4596b62 100644 --- a/roles/webserver/tasks/start_service.yml +++ b/roles/webserver/tasks/start_service.yml @@ -1,4 +1,15 @@ --- +- name: Prune Docker system before starting services + ansible.builtin.command: docker system prune -f --all + register: prune_output + ignore_errors: yes + changed_when: false + +- name: Debug - Show Docker prune output + ansible.builtin.debug: + var: prune_output + verbosity: 1 + - name: Ensure services destination directory exists ansible.builtin.file: path: "{{ server_services_dir }}"