--- # Nightly: pull and recreate Docker Compose stacks, then prune unused images. # Add or remove a stack by editing the list for its host below. # # A stack that still fails after retries does not stop the rest of that # host's stacks or the other hosts. Failures are listed at the end and # mark the host as failed in the recap. - name: Update Docker Compose stacks hosts: killer2.ki5bhv.com:docker.ki5bhv.com:proxy-server.ki5bhv.com become: true vars: stacks_by_host: killer2.ki5bhv.com: - /home/justin/docker/qbits - /home/justin/docker/homarr - /home/justin/docker/wireguard - /home/justin/docker/beszel - /home/justin/docker/cup - /home/justin/docker/ntfy - /home/justin/docker/vaultwarden - /home/justin/docker/uptime-kuma - /home/justin/docker/overseerr - /home/justin/docker/portainer - /home/justin/docker/it-tools - /home/justin/docker/termix - /home/justin/docker/netalertx - /home/justin/docker/wavelog - /home/justin/docker/kometa - /home/justin/docker/tautulli - /home/justin/docker/gaseous docker.ki5bhv.com: # capital D on this host - /home/justin/Docker/code-server - /home/justin/Docker/audio-book - /home/justin/Docker/commanfeed # Not listed on purpose: windows and minecraft are kept stopped # ("created"), and an update would start them. proxy-server.ki5bhv.com: - /home/justin/docker/nginx-proxy stacks: "{{ stacks_by_host[inventory_hostname] | default([]) }}" tasks: - name: Pull and recreate stack community.docker.docker_compose_v2: project_src: "{{ item }}" pull: always recreate: auto loop: "{{ stacks }}" loop_control: label: "{{ item | basename }}" pause: 1 register: stack_results retries: 3 delay: 5 until: stack_results is not failed ignore_errors: true - name: Prune non-dangling images community.docker.docker_prune: containers: false images: true images_filters: dangling: false networks: false volumes: false builder_cache: false - name: Fail if any stack did not update vars: failed_stacks: >- {{ stack_results.results | selectattr('failed', 'defined') | selectattr('failed') | map(attribute='item') | map('basename') | list }} ansible.builtin.fail: msg: "Stacks that failed to update: {{ failed_stacks | join(', ') }}" when: failed_stacks | length > 0