From fa48411ae55107e48cdee4b8dcd0ceee424f9420 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Sat, 27 Jun 2026 13:59:28 +0200 Subject: [PATCH] fix(sys-svc-compose): wipe stale NFS volume state on dev/act swarm redeploy Swarm reuses NFS-backed state across cluster rebuilds. A role then reads config persisted from a prior cluster while its database (a node-local volume) is fresh, causing install drift and stale-credential loops. Wipe each NFS-backed volume subdir before pre-create, gated to dev/act via RUNTIME so production state is never touched. Hoist the shared swarm and NFS guards to the include's when, and fold the per-item mapping check into the loop via selectattr, so the two tasks no longer repeat identical conditions. Co-Authored-By: Claude Opus 4.8 --- roles/sys-svc-compose/tasks/main.yml | 13 +++++++++++-- roles/sys-svc-compose/tasks/utils/nfs_prep.yml | 17 ++++++++--------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/roles/sys-svc-compose/tasks/main.yml b/roles/sys-svc-compose/tasks/main.yml index 586071a09e..fb7a6369a4 100644 --- a/roles/sys-svc-compose/tasks/main.yml +++ b/roles/sys-svc-compose/tasks/main.yml @@ -26,8 +26,17 @@ include_tasks: "02_stack_host_prep.yml" when: IS_STACK_HOST | bool -- name: "Pre-create NFS subdirs declared by '{{ application_id }}' (swarm + NFS backend only)" - include_tasks: "utils/nfs_prep.yml" +- name: "Prepare NFS subdirs for '{{ application_id }}' (wipe stale in dev/act, then pre-create; swarm + NFS only)" + include_tasks: + file: "utils/nfs_prep.yml" + apply: + delegate_to: "{{ (groups['svc-storage-nfs-server'] | default([]))[0] | default(inventory_hostname) }}" + run_once: true + when: + - DEPLOYMENT_MODE == 'swarm' + - (storage.backend | default('local')) == 'nfs' + - (groups['svc-storage-nfs-server'] | default([])) | length > 0 + - application_id not in lookup('roles_with_default_placement', 'manager') - name: "Ensure that {{ lookup('container', application_id, 'directories.instance') }} is up" include_tasks: "utils/up.yml" diff --git a/roles/sys-svc-compose/tasks/utils/nfs_prep.yml b/roles/sys-svc-compose/tasks/utils/nfs_prep.yml index b37001e1a0..e4147453cb 100644 --- a/roles/sys-svc-compose/tasks/utils/nfs_prep.yml +++ b/roles/sys-svc-compose/tasks/utils/nfs_prep.yml @@ -1,4 +1,11 @@ --- +- name: "Wipe stale NFS data for '{{ application_id }}' volume '{{ item.key }}' before swarm (re)deploy (dev/act only)" + ansible.builtin.file: + path: "{{ STORAGE_NFS_STATE_PATH }}/{{ item.value.name | default(item.key) }}" + state: absent + loop: "{{ (lookup('compose_volumes', application_id) | from_yaml).volumes | default({}) | dict2items | selectattr('value', 'mapping') | list }}" + when: RUNTIME in ['dev', 'act'] + - name: "Pre-create NFS subdir for '{{ application_id }}' volume '{{ item.key }}' on the NFS server" ansible.builtin.file: path: "{{ STORAGE_NFS_STATE_PATH }}/{{ item.value.name | default(item.key) }}" @@ -6,12 +13,4 @@ owner: "{{ (item.value.nfs | default({})).uid | default('0') | string }}" group: "{{ (item.value.nfs | default({})).gid | default('0') | string }}" mode: "{{ (item.value.nfs | default({})).mode | default('0755') }}" - delegate_to: "{{ (groups['svc-storage-nfs-server'] | default([]))[0] | default(inventory_hostname) }}" - run_once: true - loop: "{{ (lookup('compose_volumes', application_id) | from_yaml).volumes | default({}) | dict2items }}" - when: - - DEPLOYMENT_MODE == 'swarm' - - (storage.backend | default('local')) == 'nfs' - - (groups['svc-storage-nfs-server'] | default([])) | length > 0 - - item.value is mapping - - application_id not in lookup('roles_with_default_placement', 'manager') + loop: "{{ (lookup('compose_volumes', application_id) | from_yaml).volumes | default({}) | dict2items | selectattr('value', 'mapping') | list }}"