mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-06 10:59:59 +00:00
Two probes that describe a host were re-running per application. Measured in CI run wp-swarm-tor2: 42 invocations of the pip probe and 44 of the NFS assert. sys-pip-install guarded only its dependency include. Everything expensive sat below that guard in main.yml, unguarded: resolving the interpreter, probing pip for --break-system-packages, checking for `packaging` and bootstrapping it. All four ran on every one of the 21 include sites. They move into 00_core.yml, where the existing `when: run_once_sys_pip_install is not defined` covers them, and main.yml keeps the guarded include and the pip task itself. The role recap reads sys-pip-install ---- 87.35s. The two facts this freezes per host are run constants: ansible_python_interpreter is pinned once in group_vars/all/00_general.yml and no call site overrides it, and all 21 sites pass global_install: true. main.yml now defends the probe fact with `| default(false)` the way 00_core.yml already did, because the probe sits behind `when: global_install | bool` and a first invocation with false would otherwise leave it undefined for every later one. The NFS assert emulated a per-host check with run_once plus delegate_to over groups['svc-swarm-node'], and the include it lives in happens per application. It becomes a plain per-host task in sys-svc-compose/00_core.yml, which main.yml already gates once per host per play: 44 instances and 132 remote commands become 4 and 4. Dropping run_once also removes a real fragility — at log line 35355 only wrk-01 and wrk-02 reach the include because mgr-01's flag is already set, so run_once there designates a host that skipped. It reaches the same hosts as the loop it replaces, measured rather than assumed: sys-svc-compose/00_core fires only on mgr-01, wrk-01 and wrk-02, the backup play never runs it, and nfs-server and bkp-01 never execute it. The two conditions that do not travel are a per-application volume count, meaningless for a per-host check, and an exemption for manager-placed roles — mgr-01 answered the assert ok 14 times out of 14, so the exemption was hiding nothing. The assert is appended to 00_core.yml rather than prepended: utils/once/flag.yml must stay that file's first task for test_service_core_first_task_run_once. Worth 128.6s: 84.6s from the pip probe and 44.0s from the assert. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
41 lines
2.1 KiB
YAML
41 lines
2.1 KiB
YAML
---
|
|
- name: "📁 Pre-create NFS subdirs for '{{ application_id }}'"
|
|
ansible.builtin.file:
|
|
path: "{{ STORAGE_NFS_STATE_PATH }}/{{ item.value.name | default(item.key) }}"
|
|
state: directory
|
|
owner: "{{ (item.value['x-infinito-nfs'] | default({})).uid | default(omit) }}"
|
|
group: "{{ (item.value['x-infinito-nfs'] | default({})).gid | default(omit) }}"
|
|
mode: "{{ (item.value['x-infinito-nfs'] | default({})).mode | default(omit) }}"
|
|
delegate_to: "{{ (groups['svc-storage-nfs-server'] | default([]))[0] | default(inventory_hostname) }}"
|
|
run_once: true # nocheck: include-uniform-apply-keyword (per-task delegation targets differ)
|
|
loop: "{{ (lookup('compose_volumes') | from_yaml).volumes | default({}) | dict2items }}"
|
|
loop_control:
|
|
label: "{{ item.key }}"
|
|
when:
|
|
- DEPLOYMENT_MODE == 'swarm'
|
|
- (storage.backend | default('local')) == 'nfs'
|
|
- (groups['svc-storage-nfs-server'] | default([])) | length > 0
|
|
- item.value is mapping
|
|
- item.value.driver_opts is defined
|
|
- application_id not in lookup('roles_with_placement', 'manager')
|
|
|
|
- name: "🔁 Materialize NFS subdirs for '{{ application_id }}' on every swarm node"
|
|
ansible.builtin.file:
|
|
path: "{{ DIR_VAR_LIB }}/{{ item.0.value.name | default(item.0.key) }}"
|
|
state: directory
|
|
owner: "{{ (item.0.value['x-infinito-nfs'] | default({})).uid | default(omit) }}"
|
|
group: "{{ (item.0.value['x-infinito-nfs'] | default({})).gid | default(omit) }}"
|
|
mode: "{{ (item.0.value['x-infinito-nfs'] | default({})).mode | default(omit) }}"
|
|
delegate_to: "{{ item.1 }}"
|
|
run_once: true
|
|
loop: "{{ (lookup('compose_volumes') | from_yaml).volumes | default({}) | dict2items | product(groups['svc-swarm-node'] | default([])) | list }}"
|
|
loop_control:
|
|
label: "{{ item.0.key }} @ {{ item.1 }}"
|
|
when:
|
|
- DEPLOYMENT_MODE == 'swarm'
|
|
- (storage.backend | default('local')) == 'nfs'
|
|
- (groups['svc-storage-nfs-server'] | default([])) | length > 0
|
|
- item.0.value is mapping
|
|
- item.0.value.driver_opts is defined
|
|
- application_id not in lookup('roles_with_placement', 'manager')
|