From 29b1e5eb02724af5849b62e7fa4301cf9431b714 Mon Sep 17 00:00:00 2001 From: Trey Blancher Date: Sun, 12 Apr 2026 12:16:48 -0400 Subject: [PATCH] Initial commit of Docker and mailcow updates --- roles/docker_update/tasks/main.yaml | 9 +++++++++ roles/mailcow_update/handlers/main.yaml | 8 ++++++++ roles/mailcow_update/tasks/main.yaml | 25 +++++++++++++++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 roles/docker_update/tasks/main.yaml create mode 100644 roles/mailcow_update/handlers/main.yaml create mode 100644 roles/mailcow_update/tasks/main.yaml diff --git a/roles/docker_update/tasks/main.yaml b/roles/docker_update/tasks/main.yaml new file mode 100644 index 0000000..f3c05ec --- /dev/null +++ b/roles/docker_update/tasks/main.yaml @@ -0,0 +1,9 @@ +--- +- name: Pull latest images and update Docker Compose stacks + become: true + community.docker.docker_compose_v2: + project_src: "{{ item }}" + state: present + pull: always + loop: "{{ docker_compose_dirs | default([]) }}" + diff --git a/roles/mailcow_update/handlers/main.yaml b/roles/mailcow_update/handlers/main.yaml new file mode 100644 index 0000000..d5fba65 --- /dev/null +++ b/roles/mailcow_update/handlers/main.yaml @@ -0,0 +1,8 @@ +--- +- name: Restart main Docker stack + become: true + community.docker.docker_compose_v2: + # This targets the first directory in the list you defined in your host_vars + project_src: "{{ docker_compose_dirs[0] }}" + state: restarted + diff --git a/roles/mailcow_update/tasks/main.yaml b/roles/mailcow_update/tasks/main.yaml new file mode 100644 index 0000000..92f4793 --- /dev/null +++ b/roles/mailcow_update/tasks/main.yaml @@ -0,0 +1,25 @@ +--- +- name: Execute unattended Mailcow update + become: true + ansible.builtin.command: + cmd: ./update.sh --force + chdir: "{{ mailcow_dir | default('/data/mailcow') }}" + register: mailcow_first_pass + # Exit code 2 means "modules updated, run me again". Anything else is a real failure. + failed_when: mailcow_first_pass.rc not in [0, 2] + changed_when: + - mailcow_first_pass.rc == 0 + - "'Updated code is available' in mailcow_first_pass.stdout or 'Pulling' in mailcow_first_pass.stdout or 'Upgrading' in mailcow_first_pass.stdout" + notify: Restart main Docker stack + +- name: Re-run unattended Mailcow update (if modules changed) + become: true + ansible.builtin.command: + cmd: ./update.sh --force + chdir: "{{ mailcow_dir | default('/data/mailcow') }}" + # Only trigger this second pass if the first pass threw the specific restart code + when: mailcow_first_pass.rc == 2 + register: mailcow_second_pass + changed_when: + - "'Updated code is available' in mailcow_second_pass.stdout or 'Pulling' in mailcow_second_pass.stdout or 'Upgrading' in mailcow_second_pass.stdout" + notify: Restart main Docker stack