diff --git a/docs/contributing/actions/testing/suppression.md b/docs/contributing/actions/testing/suppression.md index 1b396ddf03..1cbdb30987 100644 --- a/docs/contributing/actions/testing/suppression.md +++ b/docs/contributing/actions/testing/suppression.md @@ -102,7 +102,7 @@ The placement rule is per check. The catalog "Position" column uses these labels | `seaweedfs-required` | head (first 30 lines) | [test_database_requires_seaweedfs.py](../../../../tests/integration/roles/meta/services/test_database_requires_seaweedfs.py) | Exempts a database-backed `web-app-*` role from the requirement to declare a seaweedfs object-store service. Place in the head of `roles//meta/services.yml`. Use only when the application genuinely needs no object storage. | | `tor-contract` | anywhere in file | [test_tor_contract.py](../../../../tests/lint/ansible/roles/meta/test_tor_contract.py) | Exempts a domain-serving role (`web-`/`svc-db-` prefix or explicit `domains.canonical`) from the "must declare a `tor:` block in `meta/services.yml`" contract. Reserved for roles with no onion surface, e.g. pure redirect helpers. | | `templated-conditional` | same or above | [test_no_templated_conditionals.py](../../../../tests/lint/ansible/test_no_templated_conditionals.py) | Exempts a `when` / `failed_when` / `changed_when` / `until` value that legitimately carries `{{ }}` / `{% %}`. Reserved for genuine edge cases; the default path is a bare expression. Per-item render/apply data guards belong on a `condition:` data field (honored by the sys-svc-compose render helper and `LISTMONK_SETTINGS`), not `when:`. | -| `container-address-quote` | same or above | [test_address_never_quoted.py](../../../../tests/lint/ansible/shell/container/test_address_never_quoted.py) | Allows `*_CONTAINER_ADDRESS \| quote` in a role task file. Reserved for sites that never see the swarm `$(...)` fragment (`DEPLOYMENT_MODE == 'compose'`-gated tasks, `compose_mode_force` roles) or consumers that re-evaluate the argument themselves. | +| `container-address-quote` | same or above | [test_address_never_quoted.py](../../../../tests/lint/ansible/shell/container/test_address_never_quoted.py) | Allows `*_CONTAINER_ADDRESS \| quote` in a role task file. Reserved for sites that never see the swarm `$(...)` fragment (`IS_COMPOSE_MODE`-gated tasks, `compose_mode_force` roles) or consumers that re-evaluate the argument themselves. | | `container-exec-resolver` | same or above; `argv:` target item | [test_exec_uses_resolver.py](../../../../tests/lint/ansible/shell/container/test_exec_uses_resolver.py) | Allows a `container exec` / `container inspect` target that does not route through the `container_address` lookup. Reserved for a container ID already resolved at `delegate_to` runtime (`*_LOCAL_CID`), where the lookup would return a manager-only subshell, and for deliberate bare-name partner probes gated on compose co-location. | | `container-address-needs-shell` | same or above; `argv:` target item | [test_argv_exec_needs_shell.py](../../../../tests/lint/ansible/shell/container/test_argv_exec_needs_shell.py) | Allows a `container_address`-derived target to be reached from a `command: argv:` list, which runs no shell to evaluate the swarm `$(...)` fragment. Reserved for roles pinned to compose via `compose_mode_force`, where the lookup can only ever yield a bare name. | | `container-inspect-type` | same or above; `argv:` inspect item | [test_inspect_pins_type.py](../../../../tests/lint/ansible/shell/container/test_inspect_pins_type.py) | Allows an untyped `container inspect` under `roles/`. Default path: pin `--type container`, because a role's overlay network carries the same entity name as its main container, so an untyped inspect can resolve the network and report `map has no entry for key "State"`. Use the typed subcommand (`container volume inspect` etc.) when the target genuinely is not a container. | diff --git a/group_vars/all/18_swarm.yml b/group_vars/all/18_swarm.yml index 3a3d32edc3..8cfe2895e7 100644 --- a/group_vars/all/18_swarm.yml +++ b/group_vars/all/18_swarm.yml @@ -1,6 +1,9 @@ --- DEPLOYMENT_MODE: "{{ 'swarm' if (groups['svc-swarm-node'] | default([]) | length) > 1 else 'compose' }}" +IS_COMPOSE_MODE: "{{ DEPLOYMENT_MODE == 'compose' }}" +IS_SWARM_MODE: "{{ DEPLOYMENT_MODE == 'swarm' }}" + SWARM_CLUSTER_AVAILABLE: "{{ (groups['svc-swarm-node'] | default([]) | length) > 0 }}" # Exception: a role default would be invisible to the by-path include in @@ -9,7 +12,7 @@ SWARM_CLUSTER_AVAILABLE: "{{ (groups['svc-swarm-node'] | default([]) | length) > swarm_stack_converge_retries: 600 IS_STACK_HOST: >- - {{ DEPLOYMENT_MODE == 'compose' + {{ IS_COMPOSE_MODE or inventory_hostname in (groups['svc-swarm-manager'] | default([])) }} IS_BACKUP_HOST: >- @@ -33,7 +36,7 @@ SWARM_REGISTRY_PREFIX: >- {{ (swarm.registry.host ~ ':' ~ swarm.registry.port ~ '/') if ( - DEPLOYMENT_MODE == 'swarm' + IS_SWARM_MODE and (swarm.registry.host | length > 0) ) else '' diff --git a/plugins/lookup/compose_only.py b/plugins/lookup/compose_only.py index 7844434e23..bf80523396 100644 --- a/plugins/lookup/compose_only.py +++ b/plugins/lookup/compose_only.py @@ -3,7 +3,7 @@ compose mode; emit nothing under swarm. A single SPOT for every service-level YAML key that is structurally incompatible with `docker stack deploy` and must therefore be omitted -when DEPLOYMENT_MODE == 'swarm'. Currently used for: +when IS_SWARM_MODE. Currently used for: * `container_name` — swarm rejects it alongside `deploy.replicas > 1` ("can't set container_name and X as container name must be unique"). diff --git a/plugins/lookup/depends_on.py b/plugins/lookup/depends_on.py index 1a844a6ea7..7241e96c40 100644 --- a/plugins/lookup/depends_on.py +++ b/plugins/lookup/depends_on.py @@ -8,7 +8,7 @@ is not allowed*. The two modes therefore need different YAML shapes: * swarm -> list form (just service names; swarm ignores depends_on ordering semantically but accepts the syntax) -Hand-writing the ``{% if DEPLOYMENT_MODE == 'swarm' %} … {% else %} … +Hand-writing the ``{% if IS_SWARM_MODE %} … {% else %} … {% endif %}`` per service is repetitive and easy to get wrong (forgot gate, wrong condition default, inconsistent indent). This lookup emits the whole block and switches on ``DEPLOYMENT_MODE`` itself. diff --git a/roles/svc-ai-lmstudio/tasks/utils/cid.yml b/roles/svc-ai-lmstudio/tasks/utils/cid.yml index e29b8fafba..86d72e93f5 100644 --- a/roles/svc-ai-lmstudio/tasks/utils/cid.yml +++ b/roles/svc-ai-lmstudio/tasks/utils/cid.yml @@ -1,7 +1,7 @@ --- - name: "🔍 Resolve the LM Studio container on '{{ lmstudio_node }}'" ansible.builtin.shell: | - {% if DEPLOYMENT_MODE == 'swarm' %} + {% if IS_SWARM_MODE %} container ps \ --filter "label=com.docker.swarm.service.name={{ lmstudio_service_name }}" \ --filter status=running \ @@ -13,7 +13,7 @@ changed_when: false retries: 30 delay: 2 - until: DEPLOYMENT_MODE == 'compose' or (lmstudio_node_cid.stdout | trim) | length > 0 + until: IS_COMPOSE_MODE or (lmstudio_node_cid.stdout | trim) | length > 0 delegate_to: "{{ lmstudio_node }}" - name: "🔧 Target '{{ lmstudio_node }}' for the next LM Studio step" diff --git a/roles/svc-ai-lmstudio/tasks/utils/nodes.yml b/roles/svc-ai-lmstudio/tasks/utils/nodes.yml index b3ee1a6726..fc50ee6264 100644 --- a/roles/svc-ai-lmstudio/tasks/utils/nodes.yml +++ b/roles/svc-ai-lmstudio/tasks/utils/nodes.yml @@ -1,7 +1,7 @@ --- - name: "🔧 Resolve the swarm service name of '{{ entity_name }}'" ansible.builtin.set_fact: - lmstudio_service_name: "{{ lookup('container_service', application_id, entity_name) if DEPLOYMENT_MODE == 'swarm' else '' }}" + lmstudio_service_name: "{{ lookup('container_service', application_id, entity_name) if IS_SWARM_MODE else '' }}" - name: "⏳ Wait until every LM Studio task has converged" ansible.builtin.include_tasks: "{{ lookup('path_absolute', 'roles/sys-svc-compose/tasks/utils/swarm/wait_converged.yml') }}" @@ -20,10 +20,10 @@ delay: 2 until: (lmstudio_node_scan.stdout | trim) | length > 0 delegate_to: "{{ STACK_HOST }}" - when: DEPLOYMENT_MODE == 'swarm' + when: IS_SWARM_MODE - name: "🔧 Set the LM Studio hosting nodes" ansible.builtin.set_fact: LMSTUDIO_HOST_NODES: >- {{ (lmstudio_node_scan.stdout_lines | map('trim') | select | list) - if DEPLOYMENT_MODE == 'swarm' else [inventory_hostname] }} + if IS_SWARM_MODE else [inventory_hostname] }} diff --git a/roles/svc-ai-lmstudio/tasks/utils/preload/node.yml b/roles/svc-ai-lmstudio/tasks/utils/preload/node.yml index d4a0aeb063..69b9715d9a 100644 --- a/roles/svc-ai-lmstudio/tasks/utils/preload/node.yml +++ b/roles/svc-ai-lmstudio/tasks/utils/preload/node.yml @@ -46,7 +46,7 @@ - name: "🐝 Re-raise the preload failure unchanged in swarm" # nocheck: rescue-recovery a timed-out transfer leaves the daemon reporting 0.00% for every further pull, and restarting the container it owns is the only lever the role has, though CI job 105558224377 shows a restart returning rc 0 without clearing it; the generic capture cannot even try, so swarm re-raises here instead, because under any_errors_fatal a rescued host keeps running while every other host is already marked failed, and compose ends the block by preloading again so an unrecovered failure still re-raises ansible.builtin.fail: msg: "{{ ansible_failed_result.msg | default('LM Studio preload failed') }}" - when: DEPLOYMENT_MODE == 'swarm' + when: IS_SWARM_MODE - name: "♻️ Recover the wedged transfer and preload again" ansible.builtin.include_tasks: utils/preload/recover.yml diff --git a/roles/svc-ai-lmstudio/vars/main.yml b/roles/svc-ai-lmstudio/vars/main.yml index cbe5c4baba..1a01d8eb02 100644 --- a/roles/svc-ai-lmstudio/vars/main.yml +++ b/roles/svc-ai-lmstudio/vars/main.yml @@ -19,7 +19,7 @@ LMSTUDIO_NFS_SERVER: "{{ (groups['svc-storage-nfs-server'] | default([]))[0] | d LMSTUDIO_SHARED_MODELS_PATH: "{{ [ STORAGE_NFS_STATE_PATH, lookup('volume', application_id, 'lmstudio_models').name ] | path_join }}" LMSTUDIO_SHARED_STAGING_PATH: "{{ [ STORAGE_NFS_STATE_PATH, '.lmstudio-staging' ] | path_join }}" LMSTUDIO_PRESEED_ENABLED: >- - {{ (DEPLOYMENT_MODE == 'swarm') + {{ (IS_SWARM_MODE) and (storage.backend == 'nfs') and ((groups['svc-storage-nfs-server'] | default([])) | length > 0) and (lookup('volume', application_id, 'lmstudio_models').nfs is not false) diff --git a/roles/svc-bkp-volume-2-local/vars/main.yml b/roles/svc-bkp-volume-2-local/vars/main.yml index 4a270a27d8..446df5ac06 100644 --- a/roles/svc-bkp-volume-2-local/vars/main.yml +++ b/roles/svc-bkp-volume-2-local/vars/main.yml @@ -83,7 +83,7 @@ BKP_VOLUME_2_LOCAL_VOLUMES_DISABLED_CLI: >- {%- endif %} BKP_VOLUME_2_LOCAL_HARD_RESTART_CLI: >- - {% if DEPLOYMENT_MODE == 'compose' and BKP_VOLUME_2_LOCAL_HARD_RESTART | length > 0 -%} + {% if IS_COMPOSE_MODE and BKP_VOLUME_2_LOCAL_HARD_RESTART | length > 0 -%} --hard-restart-projects {{ BKP_VOLUME_2_LOCAL_HARD_RESTART | join(' ') }} {%- endif %} diff --git a/roles/svc-db-mariadb/tasks/00_core.yml b/roles/svc-db-mariadb/tasks/00_core.yml index 23e761a30a..76c883e173 100644 --- a/roles/svc-db-mariadb/tasks/00_core.yml +++ b/roles/svc-db-mariadb/tasks/00_core.yml @@ -25,7 +25,7 @@ - db_info.container.State.Running retries: 30 delay: 5 - when: DEPLOYMENT_MODE == 'compose' + when: IS_COMPOSE_MODE - block: - name: "🔎 Root password reset | Check login with desired password (inside container)" diff --git a/roles/svc-db-mariadb/tasks/02_reset_root_password.yml b/roles/svc-db-mariadb/tasks/02_reset_root_password.yml index 6caf7ce756..6f5da4ac70 100644 --- a/roles/svc-db-mariadb/tasks/02_reset_root_password.yml +++ b/roles/svc-db-mariadb/tasks/02_reset_root_password.yml @@ -11,7 +11,7 @@ - name: "⏹️ Root password reset | Stop MariaDB compose container" ansible.builtin.command: "container stop {{ MARIADB_NAME }}" - when: DEPLOYMENT_MODE == 'compose' + when: IS_COMPOSE_MODE changed_when: true - name: "📏 Root password reset | Scale MariaDB swarm service to 0 replicas" @@ -21,7 +21,7 @@ {{ MARIADB_SWARM_SERVICE }} delegate_to: "{{ STACK_HOST }}" run_once: true - when: DEPLOYMENT_MODE == 'swarm' + when: IS_SWARM_MODE changed_when: true - name: "⏳ Root password reset | Wait until MariaDB swarm task fully stops" @@ -41,7 +41,7 @@ delay: 2 until: _mariadb_stopped is succeeded changed_when: false - when: DEPLOYMENT_MODE == 'swarm' + when: IS_SWARM_MODE - name: "🗑️ Root password reset | Remove stale recovery container from an aborted run" ansible.builtin.command: "container rm -f {{ MARIADB_RECOVERY_NAME }}" @@ -124,7 +124,7 @@ - name: "▶️ Root password reset | Start MariaDB compose container again" ansible.builtin.command: "container start {{ MARIADB_NAME }}" - when: DEPLOYMENT_MODE == 'compose' + when: IS_COMPOSE_MODE changed_when: true - name: "📏 Root password reset | Scale MariaDB swarm service back to 1 replica" @@ -134,5 +134,5 @@ {{ MARIADB_SWARM_SERVICE }} delegate_to: "{{ STACK_HOST }}" run_once: true - when: DEPLOYMENT_MODE == 'swarm' + when: IS_SWARM_MODE changed_when: true diff --git a/roles/svc-db-memcached/templates/service.yml.j2 b/roles/svc-db-memcached/templates/service.yml.j2 index cf91ec5014..6176911370 100644 --- a/roles/svc-db-memcached/templates/service.yml.j2 +++ b/roles/svc-db-memcached/templates/service.yml.j2 @@ -26,7 +26,7 @@ {%- endset -%} {{ _snippet | indent(indent, true) }} {%- endmacro %} -{% if DEPLOYMENT_MODE == 'compose' %} +{% if IS_COMPOSE_MODE %} {{ include_resource_for('memcached') }} {% endif %} {% set service_name = 'memcached' %} diff --git a/roles/svc-db-openldap/tasks/00_core.yml b/roles/svc-db-openldap/tasks/00_core.yml index 2b2abe2b2d..4b8006ff5d 100644 --- a/roles/svc-db-openldap/tasks/00_core.yml +++ b/roles/svc-db-openldap/tasks/00_core.yml @@ -31,7 +31,7 @@ delay: 5 timeout: "{{ lookup('timeout', 120) | int }}" state: started - when: DEPLOYMENT_MODE == 'compose' + when: IS_COMPOSE_MODE - name: 🔎 Check if current RootDN/RootPW already work ansible.builtin.shell: > diff --git a/roles/svc-db-redis/templates/service.yml.j2 b/roles/svc-db-redis/templates/service.yml.j2 index e678ee590e..81ab50548a 100644 --- a/roles/svc-db-redis/templates/service.yml.j2 +++ b/roles/svc-db-redis/templates/service.yml.j2 @@ -33,7 +33,7 @@ {%- endset -%} {{ _snippet | indent(indent, true) }} {%- endmacro %} -{% if DEPLOYMENT_MODE == 'compose' %} +{% if IS_COMPOSE_MODE %} {{ include_resource_for('redis') }} {% endif %} {% set service_name = 'redis' %} diff --git a/roles/svc-dns-unbound/templates/compose.yml.j2 b/roles/svc-dns-unbound/templates/compose.yml.j2 index 86f759571d..3c110d6f86 100644 --- a/roles/svc-dns-unbound/templates/compose.yml.j2 +++ b/roles/svc-dns-unbound/templates/compose.yml.j2 @@ -5,7 +5,7 @@ {{ lookup('compose_only', 'container_name', UNBOUND_CONTAINER) }} {{ lookup('container_image', application_id, 'unbound') }} {% include 'roles/sys-svc-container/templates/base.yml.j2' %} - {% if DEPLOYMENT_MODE == 'compose' and not (DOCKER_IN_CONTAINER | bool) %} + {% if IS_COMPOSE_MODE and not (DOCKER_IN_CONTAINER | bool) %} {{ lookup('container_ports', {'service': 'unbound', 'protocol': 'unbound', 'ip': DOCKER_BIND_HOST, 'transport': ['udp', 'tcp']}) | indent(4) }} diff --git a/roles/svc-dns-unbound/vars/main.yml b/roles/svc-dns-unbound/vars/main.yml index 75207698c0..0db8887a24 100644 --- a/roles/svc-dns-unbound/vars/main.yml +++ b/roles/svc-dns-unbound/vars/main.yml @@ -14,4 +14,4 @@ UNBOUND_FORWARD_DNS: "{{ (DOCKER_IN_CONTAINER | bool) or ('microsoft' in lookup( UNBOUND_ONION_FORWARD_ADDR: >- {{ (lookup('subnet_gateway') ~ '@' ~ lookup('config', 'svc-net-tor', 'services.tor.ports.local.dns')) - if ('svc-net-tor' in group_names and DEPLOYMENT_MODE == 'compose') else '' }} + if ('svc-net-tor' in group_names and IS_COMPOSE_MODE) else '' }} diff --git a/roles/svc-net-tor/tasks/00_core.yml b/roles/svc-net-tor/tasks/00_core.yml index b7cbc59ccb..43e22a87b1 100644 --- a/roles/svc-net-tor/tasks/00_core.yml +++ b/roles/svc-net-tor/tasks/00_core.yml @@ -106,7 +106,7 @@ chdir: "{{ lookup('container', application_id, 'directories.instance') }}" executable: /bin/bash become: true - when: DEPLOYMENT_MODE == 'compose' and (TOR_RESTART_REQUIRED | bool) + when: IS_COMPOSE_MODE and (TOR_RESTART_REQUIRED | bool) - name: "🔄 Force Tor service redeploy to apply hidden-service key / torrc changes" ansible.builtin.command: >- @@ -116,7 +116,7 @@ changed_when: _tor_swarm_update.rc == 0 become: true when: - - DEPLOYMENT_MODE == 'swarm' + - IS_SWARM_MODE - IS_STACK_HOST | bool - TOR_RESTART_REQUIRED | bool @@ -127,7 +127,7 @@ become: true when: - TOR_EGRESS_ROUTER_ENABLED | bool - - DEPLOYMENT_MODE == 'compose' or (IS_STACK_HOST | bool) + - IS_COMPOSE_MODE or (IS_STACK_HOST | bool) - name: "🧅 Verify the node onion is reachable" ansible.builtin.include_tasks: onion_reach.yml diff --git a/roles/svc-net-tor/templates/compose.yml.j2 b/roles/svc-net-tor/templates/compose.yml.j2 index 81c0ffdaec..fa2ace5239 100644 --- a/roles/svc-net-tor/templates/compose.yml.j2 +++ b/roles/svc-net-tor/templates/compose.yml.j2 @@ -11,7 +11,7 @@ TOR_HEALTHCHECK_PATH: "{{ TOR_HEALTHCHECK_PATH }}" {{ lookup('compose_only', 'container_name', TOR_CONTAINER) }} {{ lookup('container_image', application_id, 'tor') }} - {% if DEPLOYMENT_MODE == 'swarm' %} + {% if IS_SWARM_MODE %} {{ lookup('container_ports', {'service': 'tor', 'protocol': 'socks', 'mode': 'host', 'container': 'same'}, diff --git a/roles/svc-net-tor/templates/torrc.j2 b/roles/svc-net-tor/templates/torrc.j2 index 20e1dddbbb..e7572a6934 100644 --- a/roles/svc-net-tor/templates/torrc.j2 +++ b/roles/svc-net-tor/templates/torrc.j2 @@ -23,7 +23,7 @@ UseEntryGuards 0 AutomapHostsOnResolve 1 AutomapHostsSuffixes .onion VirtualAddrNetworkIPv4 {{ TOR_EGRESS_VIRTUAL_NET_IPV4 }} -{% if DEPLOYMENT_MODE == 'swarm' %} +{% if IS_SWARM_MODE %} TransPort 0.0.0.0:{{ TOR_TRANS_PORT }} DNSPort 0.0.0.0:{{ TOR_DNS_PORT }} {% else %} diff --git a/roles/svc-net-tor/vars/main.yml b/roles/svc-net-tor/vars/main.yml index f8245d1817..7c6b14bcfb 100644 --- a/roles/svc-net-tor/vars/main.yml +++ b/roles/svc-net-tor/vars/main.yml @@ -44,7 +44,7 @@ TOR_DNSMASQ_DROPIN: "/etc/systemd/system/dnsmasq.service.d/infinito-restart.conf # nocheck: host-local-fact meta/services.yml pins this role to the manager, so the fact describes the node the hidden service forwards on TOR_CONTAINER_DNS_HOST: "{{ ansible_facts['docker0']['ipv4']['address'] | default('', true) }}" # nocheck: host-local-fact meta/services.yml pins this role to the manager, so the fact describes the node the hidden service forwards on -TOR_HS_BACKEND_HOST: "{{ ansible_facts['default_ipv4']['address'] if DEPLOYMENT_MODE == 'swarm' else (TOR_CONTAINER_DNS_HOST | ternary(TOR_CONTAINER_DNS_HOST, '127.0.0.1')) +TOR_HS_BACKEND_HOST: "{{ ansible_facts['default_ipv4']['address'] if IS_SWARM_MODE else (TOR_CONTAINER_DNS_HOST | ternary(TOR_CONTAINER_DNS_HOST, '127.0.0.1')) }}" TOR_DATA_DIR: "{{ [ DIR_VAR_LIB, application_id, 'data' ] | path_join }}" diff --git a/roles/svc-prx-openresty/handlers/restart.yml b/roles/svc-prx-openresty/handlers/restart.yml index 48b14ea70e..06db361cfc 100644 --- a/roles/svc-prx-openresty/handlers/restart.yml +++ b/roles/svc-prx-openresty/handlers/restart.yml @@ -5,7 +5,7 @@ # mounted and `openresty -s reload` reads stale config. Force a task # redeploy on the manager to remount the live inode. - name: 🐳 Compose-mode force-recreate (a file bind-mount pins the inode) - when: DEPLOYMENT_MODE == 'compose' + when: IS_COMPOSE_MODE block: - name: 🔄 Force-recreate OpenResty (remounts the config bind to the inode) ansible.builtin.shell: | @@ -44,7 +44,7 @@ ('update out of sequence' not in ((openresty_swarm_update.stderr | default('')) | lower)) timeout: "{{ lookup('timeout', 600) | int }}" when: - - DEPLOYMENT_MODE == 'swarm' + - IS_SWARM_MODE - IS_STACK_HOST | bool - name: "🐛 MODE_DEBUG: wait + validate OpenResty" diff --git a/roles/svc-prx-openresty/tasks/00_core.yml b/roles/svc-prx-openresty/tasks/00_core.yml index ab217ef9eb..bb565f4e25 100644 --- a/roles/svc-prx-openresty/tasks/00_core.yml +++ b/roles/svc-prx-openresty/tasks/00_core.yml @@ -1,7 +1,7 @@ --- - include_tasks: utils/once/flag.yml -- when: DEPLOYMENT_MODE == 'swarm' +- when: IS_SWARM_MODE block: - name: "🔎 Stat the docker socket so the swarm openresty worker can be group-added to it" ansible.builtin.stat: @@ -62,7 +62,7 @@ changed_when: true delegate_to: "{{ STACK_HOST }}" when: - - DEPLOYMENT_MODE == 'swarm' + - IS_SWARM_MODE - OPENRESTY_DOCKER_SOCK_GID is defined - name: "✅ Verify that '{{ role_name }}' works" diff --git a/roles/svc-prx-openresty/templates/compose.yml.j2 b/roles/svc-prx-openresty/templates/compose.yml.j2 index b3bbe4721a..c3a4a8c458 100644 --- a/roles/svc-prx-openresty/templates/compose.yml.j2 +++ b/roles/svc-prx-openresty/templates/compose.yml.j2 @@ -13,7 +13,7 @@ LUA_PROMETHEUS_URL_KEYS: "{{ OPENRESTY_LUA_PROMETHEUS_URL_KEYS }}" {{ lookup('compose_only', 'container_name', OPENRESTY_CONTAINER) }} {{ lookup('container_image', application_id, 'openresty') }} - {% if DEPLOYMENT_MODE == 'swarm' %} + {% if IS_SWARM_MODE %} {{ lookup('container_ports', {'service': 'openresty', 'protocol': 'http', 'mode': 'host'}, {'service': 'openresty', 'protocol': 'https', 'mode': 'host'}) | indent(4) }} diff --git a/roles/svc-registry-cache/templates/compose.yml.j2 b/roles/svc-registry-cache/templates/compose.yml.j2 index 6d3f9137c7..b5534bcc61 100644 --- a/roles/svc-registry-cache/templates/compose.yml.j2 +++ b/roles/svc-registry-cache/templates/compose.yml.j2 @@ -2,7 +2,7 @@ {% set service_name = entity_name %} {{ service_name }}: {{ lookup('container_image', application_id, 'cache') }} - {% if DEPLOYMENT_MODE == 'compose' %} + {% if IS_COMPOSE_MODE %} {{ lookup('compose_only', 'container_name', REGISTRY_CACHE_CONTAINER) }} {% endif %} environment: diff --git a/roles/svc-registry-docker/tasks/00_core.yml b/roles/svc-registry-docker/tasks/00_core.yml index 286b634d9c..868fe9884b 100644 --- a/roles/svc-registry-docker/tasks/00_core.yml +++ b/roles/svc-registry-docker/tasks/00_core.yml @@ -2,7 +2,7 @@ - include_tasks: utils/once/flag.yml - name: "🔒 Pin the registry bind address to the resolved endpoint" - when: DEPLOYMENT_MODE == 'swarm' + when: IS_SWARM_MODE block: - name: "🔎 Resolve the registry endpoint address on the stack host" ansible.builtin.command: "getent ahostsv4 {{ swarm.registry.host }}" diff --git a/roles/svc-registry-docker/templates/compose.yml.j2 b/roles/svc-registry-docker/templates/compose.yml.j2 index 2a8a076403..aedb9a73e7 100644 --- a/roles/svc-registry-docker/templates/compose.yml.j2 +++ b/roles/svc-registry-docker/templates/compose.yml.j2 @@ -4,7 +4,7 @@ image: "{{ REGISTRY_IMAGE }}:{{ REGISTRY_VERSION }}" # nocheck: container-image-lookup {{ lookup('compose_only', 'container_name', REGISTRY_CONTAINER) }} {% include 'roles/sys-svc-container/templates/base.yml.j2' %} - {% if DEPLOYMENT_MODE == 'swarm' %} + {% if IS_SWARM_MODE %} environment: REGISTRY_HTTP_ADDR: "{{ REGISTRY_BIND_IP }}:{{ REGISTRY_PORT }}" {% else %} @@ -12,7 +12,7 @@ {{ lookup('container_ports', ['docker', 'registry']) | indent(4) }} {% endif %} {{ lookup('container_volumes', service_name) | indent(4) }} - {% if DEPLOYMENT_MODE == 'swarm' %} + {% if IS_SWARM_MODE %} networks: # nocheck: networks-literal hostnet: {} {% else %} @@ -20,7 +20,7 @@ {% endif %} {{ lookup('compose_volumes') }} -{% if DEPLOYMENT_MODE == 'swarm' %} +{% if IS_SWARM_MODE %} networks: # nocheck: networks-literal hostnet: external: true diff --git a/roles/svc-runner/templates/compose.yml.j2 b/roles/svc-runner/templates/compose.yml.j2 index c59a1dec11..e63ea37b1c 100644 --- a/roles/svc-runner/templates/compose.yml.j2 +++ b/roles/svc-runner/templates/compose.yml.j2 @@ -16,7 +16,7 @@ group_add: - "{{ _runner_docker_gid }}" {{ lookup('container_networks', node_local=True) | indent(4) }} - {% if DEPLOYMENT_MODE == 'swarm' %} + {% if IS_SWARM_MODE %} deploy: {{ lookup('compose_replicas', 1) }} {% endif %} diff --git a/roles/svc-swarm-node/tasks/00_core.yml b/roles/svc-swarm-node/tasks/00_core.yml index a132a977de..e7d7b3d8f5 100644 --- a/roles/svc-swarm-node/tasks/00_core.yml +++ b/roles/svc-swarm-node/tasks/00_core.yml @@ -2,7 +2,7 @@ - include_tasks: utils/once/flag.yml - name: "🐝 Swarm-only node setup (cluster bootstrap + shared CA anchor)" - when: DEPLOYMENT_MODE == 'swarm' + when: IS_SWARM_MODE block: - name: "🥾 Bootstrap docker swarm cluster" ansible.builtin.include_tasks: 00_core/bootstrap_cluster.yml diff --git a/roles/svc-virt-kata/tasks/00_core.yml b/roles/svc-virt-kata/tasks/00_core.yml index c5cb50c587..3a81a162ae 100644 --- a/roles/svc-virt-kata/tasks/00_core.yml +++ b/roles/svc-virt-kata/tasks/00_core.yml @@ -11,7 +11,7 @@ nodes: declare an svc-virt-kata group in the inventory. Without it this role runs on every host, every worker becomes a sandbox node, and the rest of the platform is evacuated onto the stack host. - when: DEPLOYMENT_MODE == 'swarm' + when: IS_SWARM_MODE - name: "📦 Install the gVisor userspace kernel (runsc)" get_url_retry: @@ -41,7 +41,7 @@ register: svc_virt_kata_default_runtime changed_when: false when: - - DEPLOYMENT_MODE == 'swarm' + - IS_SWARM_MODE - not (IS_STACK_HOST | bool) - name: "🛑 Refuse a sandbox node that still defaults to the shared kernel" @@ -55,7 +55,7 @@ per-service runtime key, so the label would promise an isolation the node cannot deliver and the agents would run on the host kernel. when: - - DEPLOYMENT_MODE == 'swarm' + - IS_SWARM_MODE - not (IS_STACK_HOST | bool) - name: "🏷️ Label this node as kata-capable" @@ -66,7 +66,7 @@ changed_when: svc_virt_kata_label.rc == 0 delegate_to: "{{ STACK_HOST }}" when: - - DEPLOYMENT_MODE == 'swarm' + - IS_SWARM_MODE - not (IS_STACK_HOST | bool) - name: "🔍 Read back the nodes that carry the sandbox label" @@ -76,7 +76,7 @@ changed_when: false delegate_to: "{{ STACK_HOST }}" run_once: true - when: DEPLOYMENT_MODE == 'swarm' + when: IS_SWARM_MODE - name: "🛑 Refuse to promise isolation that no node can carry" ansible.builtin.assert: @@ -88,4 +88,4 @@ the convergence wait gives up. This role writes the label on every node it runs on except the stack host, so put svc-virt-kata on at least one worker. run_once: true - when: DEPLOYMENT_MODE == 'swarm' + when: IS_SWARM_MODE diff --git a/roles/sys-ctl-rpr-container-hard/tasks/main.yml b/roles/sys-ctl-rpr-container-hard/tasks/main.yml index 8010afc2ac..462981fd3c 100644 --- a/roles/sys-ctl-rpr-container-hard/tasks/main.yml +++ b/roles/sys-ctl-rpr-container-hard/tasks/main.yml @@ -2,4 +2,4 @@ - include_tasks: 00_core.yml when: - run_once_sys_ctl_rpr_container_hard is not defined - - DEPLOYMENT_MODE == 'compose' + - IS_COMPOSE_MODE diff --git a/roles/sys-ctl-rpr-container-soft/tasks/main.yml b/roles/sys-ctl-rpr-container-soft/tasks/main.yml index 112bea33e2..e3deb4a3c0 100644 --- a/roles/sys-ctl-rpr-container-soft/tasks/main.yml +++ b/roles/sys-ctl-rpr-container-soft/tasks/main.yml @@ -2,4 +2,4 @@ - include_tasks: 00_core.yml when: - run_once_sys_ctl_rpr_container_soft is not defined - - DEPLOYMENT_MODE == 'compose' + - IS_COMPOSE_MODE diff --git a/roles/sys-service-terminator/tasks/01_run_one.yml b/roles/sys-service-terminator/tasks/01_run_one.yml index 6a5e13d98f..8fc33f5eb0 100644 --- a/roles/sys-service-terminator/tasks/01_run_one.yml +++ b/roles/sys-service-terminator/tasks/01_run_one.yml @@ -4,7 +4,7 @@ register: system_service_run_unit_present changed_when: false failed_when: false - when: DEPLOYMENT_MODE == 'swarm' + when: IS_SWARM_MODE - name: "🔄 Apply state (retry up to {{ SYS_SERVICE_RUNNER_RETRIES }} times)" ansible.builtin.systemd: @@ -15,5 +15,5 @@ delay: "{{ SYS_SERVICE_RUNNER_DELAY }}" until: result is not failed when: >- - DEPLOYMENT_MODE == 'compose' + IS_COMPOSE_MODE or system_service_run_unit_present.rc == 0 diff --git a/roles/sys-svc-compose/files/shell/resolve_container_id.sh b/roles/sys-svc-compose/files/shell/resolve_container_id.sh index db29c3695b..531102956c 100755 --- a/roles/sys-svc-compose/files/shell/resolve_container_id.sh +++ b/roles/sys-svc-compose/files/shell/resolve_container_id.sh @@ -5,8 +5,7 @@ # service that way and accepts no prefix matching. # # Compose-mode callers never reach this script: the `container_address` -# lookup returns the bare service name unchanged when -# DEPLOYMENT_MODE == 'compose'. +# lookup returns the bare service name unchanged in compose mode. # # Uses the project-wide `container` wrapper for every container-engine # call (per the no-raw-docker convention) so a podman substitution diff --git a/roles/sys-svc-compose/tasks/00_core.yml b/roles/sys-svc-compose/tasks/00_core.yml index a1ee2c33e2..0d5e1afcc7 100644 --- a/roles/sys-svc-compose/tasks/00_core.yml +++ b/roles/sys-svc-compose/tasks/00_core.yml @@ -49,6 +49,6 @@ ansible.builtin.command: "mountpoint -q {{ DIR_VAR_LIB }}" changed_when: false when: - - DEPLOYMENT_MODE == 'swarm' + - IS_SWARM_MODE - (storage.backend | default('local')) == 'nfs' - (groups['svc-storage-nfs-server'] | default([])) | length > 0 diff --git a/roles/sys-svc-compose/tasks/utils/_render_one_template.yml b/roles/sys-svc-compose/tasks/utils/_render_one_template.yml index f2728447e9..46b5b0ceaf 100644 --- a/roles/sys-svc-compose/tasks/utils/_render_one_template.yml +++ b/roles/sys-svc-compose/tasks/utils/_render_one_template.yml @@ -30,7 +30,7 @@ register: _role_templates_slurp when: - _tpl.condition | bool - - DEPLOYMENT_MODE == 'swarm' + - IS_SWARM_MODE no_log: "{{ MASK_CREDENTIALS_IN_LOGS | bool }}" - name: "[swarm] Ensure parent directory exists on peer for '{{ _tpl.dest }}'" @@ -40,7 +40,7 @@ mode: "0755" when: - _tpl.condition | bool - - DEPLOYMENT_MODE == 'swarm' + - IS_SWARM_MODE - not (IS_STACK_HOST | bool) - name: "[swarm] Distribute '{{ _tpl.dest }}' to swarm peers" @@ -52,6 +52,6 @@ mode: "{{ _tpl.mode }}" when: - _tpl.condition | bool - - DEPLOYMENT_MODE == 'swarm' + - IS_SWARM_MODE - not (IS_STACK_HOST | bool) no_log: "{{ MASK_CREDENTIALS_IN_LOGS | bool }}" diff --git a/roles/sys-svc-compose/tasks/utils/nfs_prep.yml b/roles/sys-svc-compose/tasks/utils/nfs_prep.yml index f7f528da7b..7500c4b34f 100644 --- a/roles/sys-svc-compose/tasks/utils/nfs_prep.yml +++ b/roles/sys-svc-compose/tasks/utils/nfs_prep.yml @@ -12,7 +12,7 @@ loop_control: label: "{{ item.key }}" when: - - DEPLOYMENT_MODE == 'swarm' + - IS_SWARM_MODE - (storage.backend | default('local')) == 'nfs' - (groups['svc-storage-nfs-server'] | default([])) | length > 0 - item.value is mapping @@ -32,7 +32,7 @@ loop_control: label: "{{ item.0.key }} @ {{ item.1 }}" when: - - DEPLOYMENT_MODE == 'swarm' + - IS_SWARM_MODE - (storage.backend | default('local')) == 'nfs' - (groups['svc-storage-nfs-server'] | default([])) | length > 0 - item.0.value is mapping diff --git a/roles/sys-svc-compose/tasks/utils/swarm/resolve_host_cid.yml b/roles/sys-svc-compose/tasks/utils/swarm/resolve_host_cid.yml index 268df29dd9..d3a270a02c 100644 --- a/roles/sys-svc-compose/tasks/utils/swarm/resolve_host_cid.yml +++ b/roles/sys-svc-compose/tasks/utils/swarm/resolve_host_cid.yml @@ -13,7 +13,7 @@ # Param: resolve_cid_filters - extra `container ps` filters for the cid lookup (default '') - name: "🔧 resolve_host_cid | resolve swarm service name for '{{ resolve_service_key }}'" ansible.builtin.set_fact: - _resolve_service_name: "{{ (resolve_service_name | default('')) or (lookup('container_service', application_id, resolve_service_key) if DEPLOYMENT_MODE == 'swarm' + _resolve_service_name: "{{ (resolve_service_name | default('')) or (lookup('container_service', application_id, resolve_service_key) if IS_SWARM_MODE else '') }}" - name: "⏳ resolve_host_cid | wait for '{{ resolve_service_key }}' to converge" @@ -35,15 +35,15 @@ delay: 2 until: (_resolve_node.stdout | trim) | length > 0 delegate_to: "{{ STACK_HOST }}" - when: DEPLOYMENT_MODE == 'swarm' + when: IS_SWARM_MODE - name: "🔧 resolve_host_cid | set {{ resolve_output_prefix }}_HOST_NODE" ansible.builtin.set_fact: - "{{ resolve_output_prefix }}_HOST_NODE": "{{ (_resolve_node.stdout | trim) if DEPLOYMENT_MODE == 'swarm' else inventory_hostname }}" + "{{ resolve_output_prefix }}_HOST_NODE": "{{ (_resolve_node.stdout | trim) if IS_SWARM_MODE else inventory_hostname }}" - name: "🔍 resolve_host_cid | resolve local container id for '{{ resolve_service_key }}'" ansible.builtin.shell: | - {% if DEPLOYMENT_MODE == 'swarm' %} + {% if IS_SWARM_MODE %} container ps \ --filter "label=com.docker.swarm.service.name={{ _resolve_service_name }}" \ --filter status=running {{ resolve_cid_filters | default('') }} \ @@ -55,7 +55,7 @@ changed_when: false retries: 30 delay: 2 - until: DEPLOYMENT_MODE == 'compose' or (_resolve_cid.stdout | trim) | length > 0 + until: IS_COMPOSE_MODE or (_resolve_cid.stdout | trim) | length > 0 delegate_to: "{{ lookup('vars', resolve_output_prefix ~ '_HOST_NODE') }}" - name: "🔧 resolve_host_cid | set {{ resolve_output_prefix }}_LOCAL_CID" diff --git a/roles/sys-svc-compose/tasks/utils/swarm/wait_converged.yml b/roles/sys-svc-compose/tasks/utils/swarm/wait_converged.yml index 16e659009e..5261a84529 100644 --- a/roles/sys-svc-compose/tasks/utils/swarm/wait_converged.yml +++ b/roles/sys-svc-compose/tasks/utils/swarm/wait_converged.yml @@ -6,7 +6,7 @@ # Param: wait_service_name - explicit swarm service name; overrides container_service(application_id, wait_service_key) for a service in another stack # Param: wait_retries - retries (default 600) # Param: wait_delay - delay seconds (default 2) -- when: DEPLOYMENT_MODE == 'swarm' +- when: IS_SWARM_MODE vars: _wait_service_name: "{{ (wait_service_name | default('')) or lookup('container_service', application_id, wait_service_key) }}" block: diff --git a/roles/sys-svc-container/handlers/main.yml b/roles/sys-svc-container/handlers/main.yml index c3037d70f3..911f0ca327 100644 --- a/roles/sys-svc-container/handlers/main.yml +++ b/roles/sys-svc-container/handlers/main.yml @@ -19,6 +19,6 @@ - networks.internet.dns | length > 0 environment: BUSYBOX_IMAGE: "{{ lookup('config', 'sys-svc-container', 'services.busybox.image') }}:{{ lookup('config', 'sys-svc-container', 'services.busybox.version') }}" - NODE_IMAGE: "{{ '' if DEPLOYMENT_MODE == 'swarm' else lookup('config', 'sys-svc-container', 'services.node.image') ~ ':' ~ lookup('config', 'sys-svc-container', + NODE_IMAGE: "{{ '' if IS_SWARM_MODE else lookup('config', 'sys-svc-container', 'services.node.image') ~ ':' ~ lookup('config', 'sys-svc-container', 'services.node.version') }}" DOMAIN: "{{ DOMAIN_PRIMARY }}" diff --git a/roles/sys-svc-container/templates/base.yml.j2 b/roles/sys-svc-container/templates/base.yml.j2 index 28212b01a0..6de18808f7 100644 --- a/roles/sys-svc-container/templates/base.yml.j2 +++ b/roles/sys-svc-container/templates/base.yml.j2 @@ -10,7 +10,7 @@ {% endif %} logging: driver: journald -{% if DEPLOYMENT_MODE == 'compose' %} +{% if IS_COMPOSE_MODE %} {% filter indent(4, True) %} {% include 'roles/sys-svc-container/templates/resource.yml.j2' %} {% endfilter %} diff --git a/roles/sys-svc-container/templates/daemon.json.j2 b/roles/sys-svc-container/templates/daemon.json.j2 index 4c22b11da0..31b781fd7e 100644 --- a/roles/sys-svc-container/templates/daemon.json.j2 +++ b/roles/sys-svc-container/templates/daemon.json.j2 @@ -1,7 +1,7 @@ {# Aggregate plain-HTTP registries (cluster build registry + Hub pull-through mirror) into a single insecure_registries list so docker accepts them. #} {% set _insecure = [] %} -{% if DEPLOYMENT_MODE == 'swarm' and (swarm.registry.host | length > 0) %} +{% if IS_SWARM_MODE and (swarm.registry.host | length > 0) %} {% set _ = _insecure.append(swarm.registry.host ~ ':' ~ swarm.registry.port) %} {% endif %} {% set _cache_hosts = groups['svc-registry-cache'] | default([]) %} @@ -27,7 +27,7 @@ {% if SYS_DOCKER_DAEMONM_MTU is defined and SYS_DOCKER_DAEMONM_MTU | int > 0 %}, "mtu": {{ SYS_DOCKER_DAEMONM_MTU | int }} {% endif %} -{% set firewall_backend = none if DEPLOYMENT_MODE == 'swarm' else SYS_SVC_CONTAINER_DOCKER_FIREWALL_BACKEND_BY_OS_FAMILY.get(ansible_facts['os_family']) %} +{% set firewall_backend = none if IS_SWARM_MODE else SYS_SVC_CONTAINER_DOCKER_FIREWALL_BACKEND_BY_OS_FAMILY.get(ansible_facts['os_family']) %} {% if firewall_backend %}, "firewall-backend": "{{ firewall_backend }}" {% endif %} @@ -49,7 +49,7 @@ {% endfor %} } -{% if DEPLOYMENT_MODE == 'swarm' and not (IS_STACK_HOST | bool) and (SANDBOX_RUNTIME | trim) in _present %}, +{% if IS_SWARM_MODE and not (IS_STACK_HOST | bool) and (SANDBOX_RUNTIME | trim) in _present %}, "default-runtime": "{{ SANDBOX_RUNTIME | trim }}" {% endif %} {% endif %} diff --git a/roles/sys-svc-mail-msmtp/tasks/enable.yml b/roles/sys-svc-mail-msmtp/tasks/enable.yml index add9db8054..a732c9c64a 100644 --- a/roles/sys-svc-mail-msmtp/tasks/enable.yml +++ b/roles/sys-svc-mail-msmtp/tasks/enable.yml @@ -4,7 +4,7 @@ - name: "✅ Assert {{ DIR_VAR_LIB }} is cluster-shared in swarm mode" ansible.builtin.assert: that: - - (DEPLOYMENT_MODE == 'compose') or ('svc-swarm-node' not in group_names) or ('svc-storage-nfs-client' in group_names) or ('svc-storage-nfs-server' in + - (IS_COMPOSE_MODE) or ('svc-swarm-node' not in group_names) or ('svc-storage-nfs-client' in group_names) or ('svc-storage-nfs-server' in group_names) fail_msg: >- sys-svc-mail-msmtp on a swarm member requires svc-storage-nfs-client diff --git a/roles/sys-svc-webserver-core/templates/nginx.conf.j2 b/roles/sys-svc-webserver-core/templates/nginx.conf.j2 index 7ee2aaa105..8451aff21b 100644 --- a/roles/sys-svc-webserver-core/templates/nginx.conf.j2 +++ b/roles/sys-svc-webserver-core/templates/nginx.conf.j2 @@ -5,7 +5,7 @@ events } http { -{% if DEPLOYMENT_MODE == 'swarm' %} +{% if IS_SWARM_MODE %} resolver 127.0.0.11 valid=10s ipv6=off; {% endif %} map $http_upgrade $connection_upgrade { diff --git a/roles/sys-token-store/tasks/write.yml b/roles/sys-token-store/tasks/write.yml index 51c6f5190f..a8015f1e70 100644 --- a/roles/sys-token-store/tasks/write.yml +++ b/roles/sys-token-store/tasks/write.yml @@ -59,7 +59,7 @@ content: "{{ {'users': sys_token_store_users_merged} | to_nice_yaml(indent=2, width=9999) }}" when: - sys_token_store_users_merged != sys_token_store_users - - DEPLOYMENT_MODE == 'swarm' + - IS_SWARM_MODE delegate_to: localhost run_once: true no_log: "{{ MASK_CREDENTIALS_IN_LOGS | bool }}" diff --git a/roles/test-e2e-playwright/tasks/02_run_one.yml b/roles/test-e2e-playwright/tasks/02_run_one.yml index 0fa0ac0e36..38089cd191 100644 --- a/roles/test-e2e-playwright/tasks/02_run_one.yml +++ b/roles/test-e2e-playwright/tasks/02_run_one.yml @@ -220,7 +220,7 @@ ['container', 'run', '--rm', '--ipc=host', '--shm-size=1g'] + ( ['--network', 'host'] - if DEPLOYMENT_MODE == 'swarm' + if IS_SWARM_MODE else ( ['--add-host=host.docker.internal:host-gateway'] + ( diff --git a/roles/test-e2e-playwright/vars/main.yml b/roles/test-e2e-playwright/vars/main.yml index 64acaaded7..7ab156e1f2 100644 --- a/roles/test-e2e-playwright/vars/main.yml +++ b/roles/test-e2e-playwright/vars/main.yml @@ -27,7 +27,7 @@ TEST_E2E_PLAYWRIGHT_PERSONAS_ARCHIVE: "/tmp/infinito-playwright-personas.tar" TEST_E2E_PLAYWRIGHT_SHARED_STAMP: "{{ TEST_E2E_PLAYWRIGHT_SHARED_DIR }}/.installed-version" TEST_E2E_PLAYWRIGHT_IS_ONION: "{{ lookup('tls', application_id, 'url.base') is search('\\.onion') }}" -TEST_E2E_PLAYWRIGHT_PROXY: "{{ ('socks5://' ~ lookup('tor_socks', '127.0.0.1' if DEPLOYMENT_MODE == 'swarm' else 'host.docker.internal')) if (TEST_E2E_PLAYWRIGHT_IS_ONION +TEST_E2E_PLAYWRIGHT_PROXY: "{{ ('socks5://' ~ lookup('tor_socks', '127.0.0.1' if IS_SWARM_MODE else 'host.docker.internal')) if (TEST_E2E_PLAYWRIGHT_IS_ONION | bool) else '' }}" TEST_E2E_PLAYWRIGHT_ONION_RUN_TIMEOUT: 5400 diff --git a/roles/web-app-akaunting/tasks/setup/compose.yml b/roles/web-app-akaunting/tasks/setup/compose.yml index 094aaa1488..994e17abd6 100644 --- a/roles/web-app-akaunting/tasks/setup/compose.yml +++ b/roles/web-app-akaunting/tasks/setup/compose.yml @@ -1,5 +1,5 @@ --- -# include-gated: when: DEPLOYMENT_MODE == "compose" +# include-gated: when: IS_COMPOSE_MODE - name: "⏹️ Akaunting setup | Stop running akaunting (compose)" ansible.builtin.shell: | set -euo pipefail diff --git a/roles/web-app-baserow/tasks/01_manager_ops.yml b/roles/web-app-baserow/tasks/01_manager_ops.yml index 695a9b2dcb..1e989bdbc6 100644 --- a/roles/web-app-baserow/tasks/01_manager_ops.yml +++ b/roles/web-app-baserow/tasks/01_manager_ops.yml @@ -34,7 +34,7 @@ changed_when: baserow_restart_after_migrate.rc == 0 when: - baserow_migrate_result.changed - - DEPLOYMENT_MODE == 'compose' + - IS_COMPOSE_MODE - name: "🔄 Restart Baserow application after applying migrations (swarm mode)" ansible.builtin.command: "container service update --force {{ lookup('container_service', application_id, BASEROW_SERVICE_NAME) }}" @@ -43,7 +43,7 @@ timeout: "{{ lookup('timeout', 600) | int }}" when: - baserow_migrate_result.changed - - DEPLOYMENT_MODE == 'swarm' + - IS_SWARM_MODE - name: "🔍 Re-resolve the container the restart replaced" ansible.builtin.include_tasks: "{{ lookup('path_absolute', 'roles/sys-svc-compose/tasks/utils/swarm/resolve_host_cid.yml') }}" diff --git a/roles/web-app-bluesky/tasks/00_core.yml b/roles/web-app-bluesky/tasks/00_core.yml index e4be3f7678..62ca2db7e5 100644 --- a/roles/web-app-bluesky/tasks/00_core.yml +++ b/roles/web-app-bluesky/tasks/00_core.yml @@ -59,8 +59,8 @@ vars: domain: "{{ BLUESKY_API_DOMAIN }}" http_port: "{{ BLUESKY_API_PORT }}" - webserver_proxy_service_key: "{{ 'pds' if DEPLOYMENT_MODE == 'swarm' else (application_id | get_entity_name) }}" - proxy_internal_port: "{{ lookup('config', application_id, 'services.api.ports.internal.http') if DEPLOYMENT_MODE == 'swarm' else '' }}" + webserver_proxy_service_key: "{{ 'pds' if IS_SWARM_MODE else (application_id | get_entity_name) }}" + proxy_internal_port: "{{ lookup('config', application_id, 'services.api.ports.internal.http') if IS_SWARM_MODE else '' }}" - name: "📂 Front proxy {{ BLUESKY_WEB_DOMAIN }} (broker if oauth2, else social-app)" include_role: @@ -72,14 +72,14 @@ webserver_proxy_service_key: >- {{ (BLUESKY_BROKER_SERVICE if (lookup('config', application_id, 'services.sso.enabled') | bool) else 'web') - if DEPLOYMENT_MODE == 'swarm' else (application_id | get_entity_name) + if IS_SWARM_MODE else (application_id | get_entity_name) }} proxy_internal_port: >- {{ (lookup('config', application_id, 'services.broker.ports.internal.http') if (lookup('config', application_id, 'services.sso.enabled') | bool) else lookup('config', application_id, 'services.web.ports.internal.http')) - if DEPLOYMENT_MODE == 'swarm' else '' + if IS_SWARM_MODE else '' }} when: BLUESKY_WEB_ENABLED | bool @@ -89,8 +89,8 @@ vars: domain: "{{ BLUESKY_VIEW_DOMAIN_FINAL }}" http_port: "{{ BLUESKY_VIEW_PORT }}" - webserver_proxy_service_key: "{{ 'view' if DEPLOYMENT_MODE == 'swarm' else (application_id | get_entity_name) }}" - proxy_internal_port: "{{ lookup('config', application_id, 'services.view.ports.internal.http') if DEPLOYMENT_MODE == 'swarm' else '' }}" + webserver_proxy_service_key: "{{ 'view' if IS_SWARM_MODE else (application_id | get_entity_name) }}" + proxy_internal_port: "{{ lookup('config', application_id, 'services.view.ports.internal.http') if IS_SWARM_MODE else '' }}" when: BLUESKY_VIEW_ENABLED | bool - name: "📁 Create native PDS administrator (oauth2 disabled, no broker auto-provision)" diff --git a/roles/web-app-decidim/templates/compose.yml.j2 b/roles/web-app-decidim/templates/compose.yml.j2 index 2f1cbc979d..709c20cb8b 100644 --- a/roles/web-app-decidim/templates/compose.yml.j2 +++ b/roles/web-app-decidim/templates/compose.yml.j2 @@ -19,7 +19,7 @@ {{ lookup('container_networks') | indent(4) }} {{ lookup('container_extra_hosts', extra_hosts=( [lookup('config', 'web-app-seaweedfs', 'domains.canonical.api') ~ ':host-gateway'] - if DEPLOYMENT_MODE == 'compose' else [] + if IS_COMPOSE_MODE else [] )) | indent(4) }} {{ lookup('container_depends_on', application_id) | indent(4) }} {{ lookup('container_healthcheck', service_name) | indent(4) }} diff --git a/roles/web-app-discourse/handlers/stack_host.yml b/roles/web-app-discourse/handlers/stack_host.yml index e6b013829d..7ed95ae37a 100644 --- a/roles/web-app-discourse/handlers/stack_host.yml +++ b/roles/web-app-discourse/handlers/stack_host.yml @@ -23,7 +23,7 @@ register: result when: - DISCOURSE_DATABASE_IS_SHARED | bool - - DEPLOYMENT_MODE == 'compose' + - IS_COMPOSE_MODE - name: "🔨 {{ DISCOURSE_LAUNCHER_ACTION }} discourse" shell: > diff --git a/roles/web-app-erpnext/tasks/02_bench_bootstrap/create_site.yml b/roles/web-app-erpnext/tasks/02_bench_bootstrap/create_site.yml index 85183dcdcd..5114476d79 100644 --- a/roles/web-app-erpnext/tasks/02_bench_bootstrap/create_site.yml +++ b/roles/web-app-erpnext/tasks/02_bench_bootstrap/create_site.yml @@ -39,7 +39,7 @@ {{ ERPNEXT_QUEUE_SHORT_CONTAINER }} \ {{ ERPNEXT_QUEUE_LONG_CONTAINER }} changed_when: false - when: DEPLOYMENT_MODE == 'compose' + when: IS_COMPOSE_MODE - name: "🔄 restart Frappe services to pick up newly-installed app (swarm mode)" ansible.builtin.command: >- @@ -53,7 +53,7 @@ - queue-long changed_when: false timeout: "{{ lookup('timeout', 600) | int }}" - when: DEPLOYMENT_MODE == 'swarm' + when: IS_SWARM_MODE - name: "🔍 Re-resolve ERPNext backend node + CID after restart" ansible.builtin.include_tasks: "{{ lookup('path_absolute', 'roles/sys-svc-compose/tasks/utils/swarm/resolve_host_cid.yml') }}" diff --git a/roles/web-app-erpnext/tasks/03_oidc.yml b/roles/web-app-erpnext/tasks/03_oidc.yml index 67c16859bc..82a910ab8c 100644 --- a/roles/web-app-erpnext/tasks/03_oidc.yml +++ b/roles/web-app-erpnext/tasks/03_oidc.yml @@ -30,7 +30,7 @@ changed_when: true when: - "'OIDC_SLK_CHANGED' in erpnext_oidc_apply.stdout" - - DEPLOYMENT_MODE == 'compose' + - IS_COMPOSE_MODE timeout: "{{ lookup('timeout', 120) | int }}" - name: "🔄 Restart Frappe on Social Login Key change (swarm)" @@ -39,7 +39,7 @@ changed_when: true when: - "'OIDC_SLK_CHANGED' in erpnext_oidc_apply.stdout" - - DEPLOYMENT_MODE == 'swarm' + - IS_SWARM_MODE timeout: "{{ lookup('timeout', 600) | int }}" - name: "🔍 Re-resolve ERPNext backend node + CID after OIDC restart" diff --git a/roles/web-app-fider/tasks/01_setup_oidc.yml b/roles/web-app-fider/tasks/01_setup_oidc.yml index 2985fc2793..1278978b14 100644 --- a/roles/web-app-fider/tasks/01_setup_oidc.yml +++ b/roles/web-app-fider/tasks/01_setup_oidc.yml @@ -12,7 +12,7 @@ port: "{{ lookup('config', application_id, 'services.fider.ports.local.http') }}" delay: 5 timeout: "{{ lookup('timeout', 300) | int }}" - when: DEPLOYMENT_MODE == 'compose' + when: IS_COMPOSE_MODE - name: "⏳ Wait for {{ application_id }} HTTP endpoint (swarm in-container)" ansible.builtin.shell: > # nocheck: container-exec-resolver runtime-resolved CID, delegated to the hosting node @@ -23,7 +23,7 @@ delay: 5 until: fider_http_ready.rc == 0 delegate_to: "{{ FIDER_HOST_NODE }}" - when: DEPLOYMENT_MODE == 'swarm' + when: IS_SWARM_MODE - name: "🔎 Fider | Check if tenant is already initialized" database_query: @@ -42,7 +42,7 @@ body: "{{ FIDER_TENANT_BOOTSTRAP_BODY }}" status_code: [200, 201] when: - - DEPLOYMENT_MODE == 'compose' + - IS_COMPOSE_MODE - (fider_tenant_count.rows[0][0] | int) == 0 - name: "🥾 Fider | Bootstrap initial tenant via API (swarm, routing-mesh port)" @@ -56,7 +56,7 @@ changed_when: true delegate_to: "{{ FIDER_HOST_NODE }}" when: - - DEPLOYMENT_MODE == 'swarm' + - IS_SWARM_MODE - (fider_tenant_count.rows[0][0] | int) == 0 - name: "📁 Fider | Create admin user (bypass email verification)" diff --git a/roles/web-app-friendica/templates/compose.yml.j2 b/roles/web-app-friendica/templates/compose.yml.j2 index 2623460fae..867c17e22e 100644 --- a/roles/web-app-friendica/templates/compose.yml.j2 +++ b/roles/web-app-friendica/templates/compose.yml.j2 @@ -9,7 +9,7 @@ FRIENDICA_VERSION: "{{ FRIENDICA_VERSION }}" environment: FRIENDICA_CONFIG_FILE: "{{ FRIENDICA_CONFIG_FILE }}" - {% if DEPLOYMENT_MODE == 'swarm' %} + {% if IS_SWARM_MODE %} TASK_SLOT: "{% raw %}{{.Task.Slot}}{% endraw %}" {% endif %} {% include 'roles/sys-svc-container/templates/base.yml.j2' %} diff --git a/roles/web-app-funkwhale/templates/compose.yml.j2 b/roles/web-app-funkwhale/templates/compose.yml.j2 index 813ccd6228..2d9f832e47 100644 --- a/roles/web-app-funkwhale/templates/compose.yml.j2 +++ b/roles/web-app-funkwhale/templates/compose.yml.j2 @@ -56,7 +56,7 @@ {{ lookup('container_image', application_id, 'typesense') }} {{ lookup('container_volumes', service_name) | indent(4) }} command: --data-dir /data --enable-cors --api-key {{ FUNKWHALE_TYPESENSE_API_KEY }} - {% if DEPLOYMENT_MODE == 'compose' %} + {% if IS_COMPOSE_MODE %} profiles: - typesense {% endif %} diff --git a/roles/web-app-gitea/templates/compose.yml.j2 b/roles/web-app-gitea/templates/compose.yml.j2 index 84d77ad08b..277756b97c 100644 --- a/roles/web-app-gitea/templates/compose.yml.j2 +++ b/roles/web-app-gitea/templates/compose.yml.j2 @@ -63,6 +63,6 @@ {{ lookup('compose_networks') }} {% if GITEA_MCP_ENABLED | bool %} {{ GITEA_MCP_UPSTREAM_NETWORK }}: - driver: {{ 'overlay' if DEPLOYMENT_MODE == 'swarm' else 'bridge' }} + driver: {{ 'overlay' if IS_SWARM_MODE else 'bridge' }} internal: true {% endif %} diff --git a/roles/web-app-gitlab/tasks/01_config.yml b/roles/web-app-gitlab/tasks/01_config.yml index 66229b5466..c68194fa91 100644 --- a/roles/web-app-gitlab/tasks/01_config.yml +++ b/roles/web-app-gitlab/tasks/01_config.yml @@ -117,7 +117,7 @@ delegate_to: "{{ STACK_HOST }}" run_once: true register: gitlab_hostkeys_slurp - when: DEPLOYMENT_MODE == 'swarm' + when: IS_SWARM_MODE no_log: "{{ MASK_CREDENTIALS_IN_LOGS | bool }}" - name: "[swarm] Distribute GitLab SSH host keys to swarm peers" @@ -131,7 +131,7 @@ loop_control: label: "{{ item.item }}" when: - - DEPLOYMENT_MODE == 'swarm' + - IS_SWARM_MODE - not (IS_STACK_HOST | bool) no_log: "{{ MASK_CREDENTIALS_IN_LOGS | bool }}" notify: compose-up diff --git a/roles/web-app-hermes/tasks/00_core.yml b/roles/web-app-hermes/tasks/00_core.yml index 2b04a4f599..d76d3faa70 100644 --- a/roles/web-app-hermes/tasks/00_core.yml +++ b/roles/web-app-hermes/tasks/00_core.yml @@ -23,6 +23,6 @@ vars: assert_isolated_container: "{{ HERMES_CONTAINER }}" when: - - DEPLOYMENT_MODE == 'compose' + - IS_COMPOSE_MODE - "'svc-ai-robot' not in group_names" - lookup('config', application_id, 'services.kata.enabled') | bool diff --git a/roles/web-app-jellyfin/tasks/00_core/auth.yml b/roles/web-app-jellyfin/tasks/00_core/auth.yml index 2a623fd3a6..5b40ba7ffb 100644 --- a/roles/web-app-jellyfin/tasks/00_core/auth.yml +++ b/roles/web-app-jellyfin/tasks/00_core/auth.yml @@ -27,13 +27,13 @@ - name: "♻️ Jellyfin auth | Restart to load installed plugins (compose)" ansible.builtin.command: container restart {{ JELLYFIN_NAME }} changed_when: true - when: DEPLOYMENT_MODE == 'compose' + when: IS_COMPOSE_MODE - name: "♻️ Jellyfin auth | Restart to load installed plugins (swarm)" ansible.builtin.command: "container service update --force {{ lookup('container_service', application_id, 'jellyfin') }}" changed_when: true timeout: "{{ lookup('timeout', 600) | int }}" - when: DEPLOYMENT_MODE == 'swarm' + when: IS_SWARM_MODE - name: "🔍 Re-resolve hosting node + container id after plugin restart" ansible.builtin.include_tasks: "{{ lookup('path_absolute', 'roles/sys-svc-compose/tasks/utils/swarm/resolve_host_cid.yml') }}" @@ -53,13 +53,13 @@ - name: "♻️ Jellyfin auth | Final restart to apply auth configuration (compose)" ansible.builtin.command: container restart {{ JELLYFIN_NAME }} changed_when: true - when: DEPLOYMENT_MODE == 'compose' + when: IS_COMPOSE_MODE - name: "♻️ Jellyfin auth | Final restart to apply auth configuration (swarm)" ansible.builtin.command: "container service update --force {{ lookup('container_service', application_id, 'jellyfin') }}" changed_when: true timeout: "{{ lookup('timeout', 600) | int }}" - when: DEPLOYMENT_MODE == 'swarm' + when: IS_SWARM_MODE - name: "🔍 Wait for {{ application_id }} to reconverge after the final restart" ansible.builtin.include_tasks: "{{ lookup('path_absolute', 'roles/sys-svc-compose/tasks/utils/swarm/resolve_host_cid.yml') }}" diff --git a/roles/web-app-keycloak/meta/volumes.yml b/roles/web-app-keycloak/meta/volumes.yml index 1812ed265e..67b10d4dd5 100644 --- a/roles/web-app-keycloak/meta/volumes.yml +++ b/roles/web-app-keycloak/meta/volumes.yml @@ -5,4 +5,4 @@ realm_import: mounts: - service: keycloak target: /opt/keycloak/data/import/ - when: "{{ DEPLOYMENT_MODE == 'compose' }}" + when: "{{ IS_COMPOSE_MODE }}" diff --git a/roles/web-app-keycloak/tasks/03_manager_ops/updates.yml b/roles/web-app-keycloak/tasks/03_manager_ops/updates.yml index f345152d3a..8b255f613c 100644 --- a/roles/web-app-keycloak/tasks/03_manager_ops/updates.yml +++ b/roles/web-app-keycloak/tasks/03_manager_ops/updates.yml @@ -9,7 +9,7 @@ resolve_service_key: "{{ entity_name }}" resolve_output_prefix: KEYCLOAK resolve_compose_cid: "{{ lookup('container_address', application_id, entity_name) }}" - when: DEPLOYMENT_MODE == 'swarm' + when: IS_SWARM_MODE - name: "📂 Run Keycloak object-update routines on the freshly resolved node" ansible.builtin.include_tasks: @@ -28,7 +28,7 @@ - name: "🐳 Keycloak updates | Re-raise failure unchanged in compose (no swarm recovery)" ansible.builtin.fail: msg: "{{ ansible_failed_result.msg | default('Keycloak object update failed') }}" - when: DEPLOYMENT_MODE == 'compose' + when: IS_COMPOSE_MODE - name: "🛑 Keycloak updates | Fail after exhausting cross-node recovery retries" ansible.builtin.fail: diff --git a/roles/web-app-keycloak/tasks/04_realm_import/compose.yml b/roles/web-app-keycloak/tasks/04_realm_import/compose.yml index 43292417a7..af75710e4b 100644 --- a/roles/web-app-keycloak/tasks/04_realm_import/compose.yml +++ b/roles/web-app-keycloak/tasks/04_realm_import/compose.yml @@ -1,5 +1,5 @@ --- -# include-gated: when: DEPLOYMENT_MODE == "compose" +# include-gated: when: IS_COMPOSE_MODE - name: "⏹️ Keycloak realm-import | Stop running keycloak (compose)" ansible.builtin.shell: | set -euo pipefail diff --git a/roles/web-app-keycloak/tasks/update/01_client.yml b/roles/web-app-keycloak/tasks/update/01_client.yml index 19b01e1e40..4e1c3cfe08 100644 --- a/roles/web-app-keycloak/tasks/update/01_client.yml +++ b/roles/web-app-keycloak/tasks/update/01_client.yml @@ -46,8 +46,8 @@ kcadm_exec: "{{ KEYCLOAK_EXEC_KCADM }}" realm: "{{ KEYCLOAK_REALM }}" assert_mode: "{{ MODE_ASSERT }}" - cid_resolve_cmd: "{{ KEYCLOAK_CID_RESOLVE_CMD if DEPLOYMENT_MODE == 'swarm' else omit }}" - current_cid: "{{ KEYCLOAK_LOCAL_CID if DEPLOYMENT_MODE == 'swarm' else omit }}" + cid_resolve_cmd: "{{ KEYCLOAK_CID_RESOLVE_CMD if IS_SWARM_MODE else omit }}" + current_cid: "{{ KEYCLOAK_LOCAL_CID if IS_SWARM_MODE else omit }}" no_log: "{{ MASK_CREDENTIALS_IN_LOGS | bool }}" register: kc_client_update changed_when: false diff --git a/roles/web-app-keycloak/tasks/utils/login.yml b/roles/web-app-keycloak/tasks/utils/login.yml index fcca5d9f5b..25cba28cca 100644 --- a/roles/web-app-keycloak/tasks/utils/login.yml +++ b/roles/web-app-keycloak/tasks/utils/login.yml @@ -10,7 +10,7 @@ until: > kc_running_compose.rc == 0 and (kc_running_compose.stdout | trim) == 'true' delegate_to: "{{ inventory_hostname }}" - when: DEPLOYMENT_MODE == 'compose' + when: IS_COMPOSE_MODE - name: "🔍 Keycloak login | Resolve hosting node + container id" ansible.builtin.include_tasks: "{{ lookup('path_absolute', 'roles/sys-svc-compose/tasks/utils/swarm/resolve_host_cid.yml') }}" diff --git a/roles/web-app-keycloak/templates/env.j2 b/roles/web-app-keycloak/templates/env.j2 index 834bc6300b..b05807463c 100644 --- a/roles/web-app-keycloak/templates/env.j2 +++ b/roles/web-app-keycloak/templates/env.j2 @@ -10,7 +10,7 @@ KC_HOSTNAME_STRICT_HTTPS=false KC_PROXY_HEADERS=xforwarded -{% if DEPLOYMENT_MODE == 'swarm' %} +{% if IS_SWARM_MODE %} KC_CACHE=ispn KC_CACHE_STACK=jdbc-ping KC_CACHE_EMBEDDED_NETWORK_BIND_ADDRESS=match-address:{{ lookup('subnet_address_regex') }} diff --git a/roles/web-app-keycloak/templates/sso_proxy/container.yml.j2 b/roles/web-app-keycloak/templates/sso_proxy/container.yml.j2 index 806fb3cd63..e455abbb90 100644 --- a/roles/web-app-keycloak/templates/sso_proxy/container.yml.j2 +++ b/roles/web-app-keycloak/templates/sso_proxy/container.yml.j2 @@ -15,7 +15,7 @@ {% if (TLS_MODE | lower) == 'self_signed' and OIDC.CLIENT.ISSUER_URL.startswith('https') %} - "{{ CA_TRUST.cert_host }}:{{ CA_TRUST.cert_container }}:ro" {% endif %} -{% if DEPLOYMENT_MODE == 'swarm' %} +{% if IS_SWARM_MODE %} {{ lookup('container_networks', provider_self_alias=False) | indent(4) }} deploy: placement: diff --git a/roles/web-app-listmonk/tasks/utils/mcp.yml b/roles/web-app-listmonk/tasks/utils/mcp.yml index 9115eab345..97717677bc 100644 --- a/roles/web-app-listmonk/tasks/utils/mcp.yml +++ b/roles/web-app-listmonk/tasks/utils/mcp.yml @@ -39,11 +39,11 @@ - restart - "{{ LISTMONK_IDENTITY_LOCAL_CID }}" # nocheck: container-exec-resolver changed_when: true - when: DEPLOYMENT_MODE == 'compose' + when: IS_COMPOSE_MODE delegate_to: "{{ LISTMONK_IDENTITY_HOST_NODE }}" - name: "🔄 swarm | force an update of the Listmonk service" ansible.builtin.command: "container service update --force {{ lookup('container_service', application_id, 'listmonk') }}" changed_when: true timeout: "{{ lookup('timeout', 600) | int }}" - when: DEPLOYMENT_MODE == 'swarm' + when: IS_SWARM_MODE diff --git a/roles/web-app-magento/tasks/01_setup.yml b/roles/web-app-magento/tasks/01_setup.yml index ffa05cedc6..d6cc735f0c 100644 --- a/roles/web-app-magento/tasks/01_setup.yml +++ b/roles/web-app-magento/tasks/01_setup.yml @@ -105,7 +105,7 @@ register: magento_nginx_restart_compose changed_when: magento_nginx_restart_compose.rc == 0 when: - - DEPLOYMENT_MODE == 'compose' + - IS_COMPOSE_MODE - magento_nginx_conf is changed or magento_install is changed - name: "🔄 Restart nginx so it picks up Magento's vhost (swarm)" @@ -116,5 +116,5 @@ changed_when: magento_nginx_restart_swarm.rc == 0 timeout: "{{ lookup('timeout', 600) | int }}" when: - - DEPLOYMENT_MODE == 'swarm' + - IS_SWARM_MODE - magento_nginx_conf is changed or magento_install is changed diff --git a/roles/web-app-mailu/meta/services.yml b/roles/web-app-mailu/meta/services.yml index 2ec469866e..68595fda11 100644 --- a/roles/web-app-mailu/meta/services.yml +++ b/roles/web-app-mailu/meta/services.yml @@ -88,7 +88,7 @@ redis: disabled: true enabled: true # nocheck: dynamic-flag # Exception: central redis overlay adds VIP pressure on manager-pinned mailu; embedded redis avoids it. - shared: "{{ ('svc-db-redis' in group_names) and (DEPLOYMENT_MODE == 'compose') }}" + shared: "{{ ('svc-db-redis' in group_names) and (IS_COMPOSE_MODE) }}" cpus: "0.2" mem_reservation: 256m mem_limit: 512m @@ -97,7 +97,7 @@ redis: # nocheck: dynamic-flag enabled+shared (not the `in group_names` form) marks svc-dns-unbound `required` so the loader deploys it every compose round; reverting reintroduces the admin DNS hang. unbound: bond: 1 - enabled: "{{ DEPLOYMENT_MODE == 'compose' }}" + enabled: "{{ IS_COMPOSE_MODE }}" shared: true # nocheck: playwright-service-flag — DB engine, covered by role-local integration tests mariadb: diff --git a/roles/web-app-mailu/tasks/00_core.yml b/roles/web-app-mailu/tasks/00_core.yml index c2e0ecd7d6..7af224ef91 100644 --- a/roles/web-app-mailu/tasks/00_core.yml +++ b/roles/web-app-mailu/tasks/00_core.yml @@ -40,7 +40,7 @@ - name: "🔍 Resolve central mariadb/redis VIPs for admin extra_hosts (swarm)" include_tasks: 01_swarm_resolve_peer_vips.yml - when: DEPLOYMENT_MODE == 'swarm' + when: IS_SWARM_MODE - name: "🧩 load docker, db and proxy for {{ application_id }}" include_role: diff --git a/roles/web-app-mailu/templates/compose.yml.j2 b/roles/web-app-mailu/templates/compose.yml.j2 index 70479a6539..97e68840a0 100644 --- a/roles/web-app-mailu/templates/compose.yml.j2 +++ b/roles/web-app-mailu/templates/compose.yml.j2 @@ -9,7 +9,7 @@ {{ lookup('container_volumes', service_name) | indent(4) }} {{ lookup('container_depends_on', application_id) | indent(4) }} {{ lookup('container_networks') | indent(4) }} - {% if DEPLOYMENT_MODE == 'compose' %} + {% if IS_COMPOSE_MODE %} webmail: radicale: dns: @@ -25,7 +25,7 @@ {{ lookup('container_depends_on', application_id, extra={ 'front': {'condition': 'service_started'}, }) | indent(4) }} - {% if DEPLOYMENT_MODE == 'compose' %} + {% if IS_COMPOSE_MODE %} dns: - {{ MAILU_DNS_RESOLVER }} {% else %} @@ -46,7 +46,7 @@ {% include 'roles/sys-svc-container/templates/base.yml.j2' %} {{ lookup('container_volumes', service_name) | indent(4) }} {{ lookup('depends_on', ['front']) }} - {% if DEPLOYMENT_MODE == 'compose' %} + {% if IS_COMPOSE_MODE %} dns: - {{ MAILU_DNS_RESOLVER }} {% endif %} @@ -59,7 +59,7 @@ {% include 'roles/sys-svc-container/templates/base.yml.j2' %} {{ lookup('container_volumes', service_name) | indent(4) }} {{ lookup('depends_on', ['front']) }} - {% if DEPLOYMENT_MODE == 'compose' %} + {% if IS_COMPOSE_MODE %} dns: - {{ MAILU_DNS_RESOLVER }} {% endif %} @@ -71,12 +71,12 @@ {{ lookup('compose_only', 'container_name', MAILU_OLETOOLS_CONTAINER_ADDRESS) }} {{ lookup('container_image', application_id, 'oletools', image=MAILU_DOCKER_FLAVOR ~ '/oletools', version=MAILU_VERSION) }} hostname: oletools - {% if DEPLOYMENT_MODE == 'compose' %} + {% if IS_COMPOSE_MODE %} dns: - {{ MAILU_DNS_RESOLVER }} {% endif %} {{ lookup('container_networks') | indent(4) }} - {% if DEPLOYMENT_MODE == 'compose' %} + {% if IS_COMPOSE_MODE %} noinet: {% endif %} @@ -87,12 +87,12 @@ {% include 'roles/sys-svc-container/templates/base.yml.j2' %} {{ lookup('container_volumes', service_name) | indent(4) }} {{ lookup('depends_on', ['front', 'antivirus'] + (['redis'] if lookup('engine', 'redis', application_id, 'local') else [])) }} - {% if DEPLOYMENT_MODE == 'compose' %} + {% if IS_COMPOSE_MODE %} dns: - {{ MAILU_DNS_RESOLVER }} {% endif %} {{ lookup('container_networks') | indent(4) }} - {% if DEPLOYMENT_MODE == 'compose' %} + {% if IS_COMPOSE_MODE %} noinet: {% endif %} @@ -102,7 +102,7 @@ {{ lookup('container_image', application_id, 'antivirus') }} {% include 'roles/sys-svc-container/templates/base.yml.j2' %} {{ lookup('container_volumes', service_name) | indent(4) }} - {% if DEPLOYMENT_MODE == 'compose' %} + {% if IS_COMPOSE_MODE %} dns: - {{ MAILU_DNS_RESOLVER }} {% endif %} @@ -114,12 +114,12 @@ {{ lookup('container_image', application_id, 'webdav', image=MAILU_DOCKER_FLAVOR ~ '/radicale', version=MAILU_VERSION) }} {% include 'roles/sys-svc-container/templates/base.yml.j2' %} {{ lookup('container_volumes', service_name) | indent(4) }} - {% if DEPLOYMENT_MODE == 'compose' %} + {% if IS_COMPOSE_MODE %} dns: - {{ MAILU_DNS_RESOLVER }} {% endif %} {{ lookup('container_networks') | indent(4) }} - {% if DEPLOYMENT_MODE == 'compose' %} + {% if IS_COMPOSE_MODE %} radicale: {% endif %} @@ -130,7 +130,7 @@ {{ lookup('container_volumes', service_name) | indent(4) }} {% include 'roles/sys-svc-container/templates/base.yml.j2' %} {{ lookup('depends_on', ['admin', 'smtp', 'imap']) }} - {% if DEPLOYMENT_MODE == 'compose' %} + {% if IS_COMPOSE_MODE %} dns: - {{ MAILU_DNS_RESOLVER }} {% endif %} @@ -143,18 +143,18 @@ {% include 'roles/sys-svc-container/templates/base.yml.j2' %} {{ lookup('container_volumes', service_name) | indent(4) }} {{ lookup('depends_on', ['imap', 'front']) }} - {% if DEPLOYMENT_MODE == 'compose' %} + {% if IS_COMPOSE_MODE %} dns: - {{ MAILU_DNS_RESOLVER }} {% endif %} {{ lookup('container_networks') | indent(4) }} - {% if DEPLOYMENT_MODE == 'compose' %} + {% if IS_COMPOSE_MODE %} webmail: {% endif %} {{ lookup('compose_volumes') }} {{ lookup('compose_networks') }} - {% if DEPLOYMENT_MODE == 'compose' %} + {% if IS_COMPOSE_MODE %} radicale: driver: bridge webmail: diff --git a/roles/web-app-matomo/tasks/03_install_path.yml b/roles/web-app-matomo/tasks/03_install_path.yml index b5a746dd88..0377f2ccdd 100644 --- a/roles/web-app-matomo/tasks/03_install_path.yml +++ b/roles/web-app-matomo/tasks/03_install_path.yml @@ -28,7 +28,7 @@ meta: flush_handlers - name: "🐝 Matomo install | Swarm: restart matomo so patched config is re-read" - when: DEPLOYMENT_MODE == 'swarm' + when: IS_SWARM_MODE block: - name: "🐝 Matomo install | Swarm: force-restart matomo service" ansible.builtin.command: >- diff --git a/roles/web-app-matomo/tasks/04_bootstrap.yml b/roles/web-app-matomo/tasks/04_bootstrap.yml index 46fc81e372..3eadc833cc 100644 --- a/roles/web-app-matomo/tasks/04_bootstrap.yml +++ b/roles/web-app-matomo/tasks/04_bootstrap.yml @@ -9,7 +9,7 @@ (matomo_token_value | default('') | string | trim) if (matomo_token_value is defined and (matomo_token_value | string | trim) != '') else ( - ((matomo_bootstrap_compose.stdout if DEPLOYMENT_MODE == 'compose' else matomo_bootstrap_swarm.stdout) | default('') | string) + ((matomo_bootstrap_compose.stdout if IS_COMPOSE_MODE else matomo_bootstrap_swarm.stdout) | default('') | string) | regex_search('(?m)^[a-f0-9]{32,64}$') | default('', true) | trim @@ -24,7 +24,7 @@ - matomo_token_value is match("^[a-f0-9]{32,64}$") fail_msg: >- Matomo bootstrap did not yield a valid token. - stdout={{ (matomo_bootstrap_compose.stdout if DEPLOYMENT_MODE == 'compose' else matomo_bootstrap_swarm.stdout) | default('') | trim }} + stdout={{ (matomo_bootstrap_compose.stdout if IS_COMPOSE_MODE else matomo_bootstrap_swarm.stdout) | default('') | trim }} when: MODE_ASSERT_LOCAL | bool - name: "💾 Matomo | Persist + inject token via sys-token-store (store + runtime users)" diff --git a/roles/web-app-matomo/tasks/utils/resolve/host_cid.yml b/roles/web-app-matomo/tasks/utils/resolve/host_cid.yml index ab1d25c796..b21e6a5936 100644 --- a/roles/web-app-matomo/tasks/utils/resolve/host_cid.yml +++ b/roles/web-app-matomo/tasks/utils/resolve/host_cid.yml @@ -9,7 +9,7 @@ delay: 2 until: > matomo_running_compose.rc == 0 and (matomo_running_compose.stdout | trim) == 'true' - when: DEPLOYMENT_MODE == 'compose' + when: IS_COMPOSE_MODE - name: "🔍 Resolve {{ application_id }} hosting node + container id" ansible.builtin.include_tasks: "{{ lookup('path_absolute', 'roles/sys-svc-compose/tasks/utils/swarm/resolve_host_cid.yml') }}" diff --git a/roles/web-app-matomo/templates/compose.yml.j2 b/roles/web-app-matomo/templates/compose.yml.j2 index e7b8ef95c7..7cc07805f0 100644 --- a/roles/web-app-matomo/templates/compose.yml.j2 +++ b/roles/web-app-matomo/templates/compose.yml.j2 @@ -19,7 +19,7 @@ {% set docker_compose_env = MATOMO_BOOTSTRAP_ENV_FILE %} {{ service_name }}: {% include 'roles/sys-svc-container/templates/base.yml.j2' %} - {% if DEPLOYMENT_MODE == 'compose' %} + {% if IS_COMPOSE_MODE %} profiles: - "{{ MATOMO_BOOTSTRAP_PROFILE }}" {% endif %} diff --git a/roles/web-app-matrix/tasks/flavor/compose/01_docker.yml b/roles/web-app-matrix/tasks/flavor/compose/01_docker.yml index 3b3cbf7d17..4f25f1a601 100644 --- a/roles/web-app-matrix/tasks/flavor/compose/01_docker.yml +++ b/roles/web-app-matrix/tasks/flavor/compose/01_docker.yml @@ -1,5 +1,5 @@ --- -# include-gated: when: DEPLOYMENT_MODE == "compose" +# include-gated: when: IS_COMPOSE_MODE - name: "🧩 load docker and db for {{ application_id }}" include_role: name: sys-stk-backend @@ -83,7 +83,7 @@ - name: "🐳 compose-mode lifecycle (pull + up)" include_tasks: 03_compose_pull_and_up.yml - when: DEPLOYMENT_MODE == 'compose' + when: IS_COMPOSE_MODE - name: "🚿 Flush handlers so the stack deploys before the Synapse wait" meta: flush_handlers diff --git a/roles/web-app-matrix/tasks/flavor/compose/02_create-and-seed-database.yml b/roles/web-app-matrix/tasks/flavor/compose/02_create-and-seed-database.yml index 24554e754a..9159a9876d 100644 --- a/roles/web-app-matrix/tasks/flavor/compose/02_create-and-seed-database.yml +++ b/roles/web-app-matrix/tasks/flavor/compose/02_create-and-seed-database.yml @@ -1,5 +1,5 @@ --- -# include-gated: when: DEPLOYMENT_MODE == "compose" +# include-gated: when: IS_COMPOSE_MODE # Expected from caller (loop): # - database_name # - database_username diff --git a/roles/web-app-matrix/tasks/flavor/compose/03_compose_pull_and_up.yml b/roles/web-app-matrix/tasks/flavor/compose/03_compose_pull_and_up.yml index 3cadf94b11..b3bdd9810a 100644 --- a/roles/web-app-matrix/tasks/flavor/compose/03_compose_pull_and_up.yml +++ b/roles/web-app-matrix/tasks/flavor/compose/03_compose_pull_and_up.yml @@ -1,5 +1,5 @@ --- -# include-gated: when: DEPLOYMENT_MODE == "compose" +# include-gated: when: IS_COMPOSE_MODE - name: 🐳 compose pull command: cmd: "compose pull" diff --git a/roles/web-app-matrix/tasks/flavor/compose/04_webserver.yml b/roles/web-app-matrix/tasks/flavor/compose/04_webserver.yml index b7f943e424..d85be65057 100644 --- a/roles/web-app-matrix/tasks/flavor/compose/04_webserver.yml +++ b/roles/web-app-matrix/tasks/flavor/compose/04_webserver.yml @@ -1,5 +1,5 @@ --- -# include-gated: when: DEPLOYMENT_MODE == "compose" +# include-gated: when: IS_COMPOSE_MODE - name: 📁 create {{ MATRIX_WELL_KNOWN_DIRECTORY }} ansible.builtin.file: path: "{{ MATRIX_WELL_KNOWN_DIRECTORY }}" diff --git a/roles/web-app-mattermost/tasks/02_keycloak.yml b/roles/web-app-mattermost/tasks/02_keycloak.yml index 2c6c7d9afb..5bb86d5921 100644 --- a/roles/web-app-mattermost/tasks/02_keycloak.yml +++ b/roles/web-app-mattermost/tasks/02_keycloak.yml @@ -21,7 +21,7 @@ --user {{ MATTERMOST_KEYCLOAK_ADMIN_USER | quote }} --password {{ MATTERMOST_KEYCLOAK_ADMIN_PASS | quote }} args: - chdir: "{{ lookup('container', 'web-app-keycloak', 'directories.instance') if DEPLOYMENT_MODE == 'compose' else omit }}" + chdir: "{{ lookup('container', 'web-app-keycloak', 'directories.instance') if IS_COMPOSE_MODE else omit }}" delegate_to: "{{ MATTERMOST_KC_HOST_NODE }}" changed_when: false @@ -33,7 +33,7 @@ -q clientId={{ OIDC.CLIENT.ID | quote }} --fields id --format csv --noquotes args: - chdir: "{{ lookup('container', 'web-app-keycloak', 'directories.instance') if DEPLOYMENT_MODE == 'compose' else omit }}" + chdir: "{{ lookup('container', 'web-app-keycloak', 'directories.instance') if IS_COMPOSE_MODE else omit }}" delegate_to: "{{ MATTERMOST_KC_HOST_NODE }}" register: mm_kc_client_uuid changed_when: false @@ -47,7 +47,7 @@ -r {{ OIDC.CLIENT.REALM | quote }} --fields name --format csv --noquotes args: - chdir: "{{ lookup('container', 'web-app-keycloak', 'directories.instance') if DEPLOYMENT_MODE == 'compose' else omit }}" + chdir: "{{ lookup('container', 'web-app-keycloak', 'directories.instance') if IS_COMPOSE_MODE else omit }}" delegate_to: "{{ MATTERMOST_KC_HOST_NODE }}" register: mm_kc_existing_mappers changed_when: false @@ -59,7 +59,7 @@ -r {{ OIDC.CLIENT.REALM | quote }} --fields id,name --format csv --noquotes args: - chdir: "{{ lookup('container', 'web-app-keycloak', 'directories.instance') if DEPLOYMENT_MODE == 'compose' else omit }}" + chdir: "{{ lookup('container', 'web-app-keycloak', 'directories.instance') if IS_COMPOSE_MODE else omit }}" delegate_to: "{{ MATTERMOST_KC_HOST_NODE }}" register: mm_kc_all_scopes changed_when: false @@ -72,7 +72,7 @@ -s name=openid -s protocol=openid-connect args: - chdir: "{{ lookup('container', 'web-app-keycloak', 'directories.instance') if DEPLOYMENT_MODE == 'compose' else omit }}" + chdir: "{{ lookup('container', 'web-app-keycloak', 'directories.instance') if IS_COMPOSE_MODE else omit }}" delegate_to: "{{ MATTERMOST_KC_HOST_NODE }}" when: "mm_kc_all_scopes.stdout_lines | select('search', ',openid$') | list | length == 0" register: mm_kc_create_openid_scope @@ -84,7 +84,7 @@ -r {{ OIDC.CLIENT.REALM | quote }} --fields id,name --format csv --noquotes args: - chdir: "{{ lookup('container', 'web-app-keycloak', 'directories.instance') if DEPLOYMENT_MODE == 'compose' else omit }}" + chdir: "{{ lookup('container', 'web-app-keycloak', 'directories.instance') if IS_COMPOSE_MODE else omit }}" delegate_to: "{{ MATTERMOST_KC_HOST_NODE }}" register: mm_kc_all_scopes changed_when: false @@ -98,7 +98,7 @@ -r {{ OIDC.CLIENT.REALM | quote }} --fields name --format csv --noquotes args: - chdir: "{{ lookup('container', 'web-app-keycloak', 'directories.instance') if DEPLOYMENT_MODE == 'compose' else omit }}" + chdir: "{{ lookup('container', 'web-app-keycloak', 'directories.instance') if IS_COMPOSE_MODE else omit }}" delegate_to: "{{ MATTERMOST_KC_HOST_NODE }}" register: mm_kc_default_scopes changed_when: false @@ -111,7 +111,7 @@ | first | trim }} -r {{ OIDC.CLIENT.REALM | quote }} args: - chdir: "{{ lookup('container', 'web-app-keycloak', 'directories.instance') if DEPLOYMENT_MODE == 'compose' else omit }}" + chdir: "{{ lookup('container', 'web-app-keycloak', 'directories.instance') if IS_COMPOSE_MODE else omit }}" delegate_to: "{{ MATTERMOST_KC_HOST_NODE }}" when: "'openid' not in mm_kc_default_scopes.stdout" @@ -131,7 +131,7 @@ -s 'config."id.token.claim"=true' -s 'config."access.token.claim"=true' args: - chdir: "{{ lookup('container', 'web-app-keycloak', 'directories.instance') if DEPLOYMENT_MODE == 'compose' else omit }}" + chdir: "{{ lookup('container', 'web-app-keycloak', 'directories.instance') if IS_COMPOSE_MODE else omit }}" delegate_to: "{{ MATTERMOST_KC_HOST_NODE }}" when: "'mattermost-id' not in mm_kc_existing_mappers.stdout" @@ -151,6 +151,6 @@ -s 'config."id.token.claim"=true' -s 'config."access.token.claim"=true' args: - chdir: "{{ lookup('container', 'web-app-keycloak', 'directories.instance') if DEPLOYMENT_MODE == 'compose' else omit }}" + chdir: "{{ lookup('container', 'web-app-keycloak', 'directories.instance') if IS_COMPOSE_MODE else omit }}" delegate_to: "{{ MATTERMOST_KC_HOST_NODE }}" when: "'mattermost-username' not in mm_kc_existing_mappers.stdout" diff --git a/roles/web-app-mattermost/tasks/utils/ai_gateway.yml b/roles/web-app-mattermost/tasks/utils/ai_gateway.yml index 12cf167c38..5f7812290f 100644 --- a/roles/web-app-mattermost/tasks/utils/ai_gateway.yml +++ b/roles/web-app-mattermost/tasks/utils/ai_gateway.yml @@ -74,7 +74,7 @@ delegate_to: "{{ STACK_HOST }}" run_once: true when: - - DEPLOYMENT_MODE == 'swarm' + - IS_SWARM_MODE - IS_STACK_HOST | bool - name: "⏳ Mattermost | Wait until every replica is back on the merged config" diff --git a/roles/web-app-minio/templates/service.yml.j2 b/roles/web-app-minio/templates/service.yml.j2 index 176f699eea..c580d7848b 100644 --- a/roles/web-app-minio/templates/service.yml.j2 +++ b/roles/web-app-minio/templates/service.yml.j2 @@ -21,7 +21,7 @@ {%- endset -%} {{ _snippet | indent(indent, true) }} {%- endmacro %} -{% if DEPLOYMENT_MODE == 'compose' %} +{% if IS_COMPOSE_MODE %} {{ include_resource_for('minio') }} {% endif %} {% set service_name = 'minio' %} diff --git a/roles/web-app-nextcloud/tasks/addons/integration_mattermost.yml b/roles/web-app-nextcloud/tasks/addons/integration_mattermost.yml index f2a0e33004..d617e9cf48 100644 --- a/roles/web-app-nextcloud/tasks/addons/integration_mattermost.yml +++ b/roles/web-app-nextcloud/tasks/addons/integration_mattermost.yml @@ -8,7 +8,7 @@ nextcloud_mm_base_url: "{{ lookup('tls', 'web-app-mattermost', 'url.base') }}" nextcloud_mm_local_url: "http://{{ DOCKER_REACH_HOST }}:{{ lookup('config', 'web-app-mattermost', 'services.mattermost.ports.local.http') }}" nextcloud_mm_redirect_path: "/apps/integration_mattermost/oauth-redirect" - nextcloud_mm_exec_chdir: "{{ lookup('container', 'web-app-mattermost', 'directories.instance') if DEPLOYMENT_MODE == 'compose' else omit }}" + nextcloud_mm_exec_chdir: "{{ lookup('container', 'web-app-mattermost', 'directories.instance') if IS_COMPOSE_MODE else omit }}" changed_when: false - name: 🔧 Provision the bidirectional Mattermost <-> Nextcloud OAuth coupling diff --git a/roles/web-app-nextcloud/templates/compose.yml.j2 b/roles/web-app-nextcloud/templates/compose.yml.j2 index c4a1edb7ee..dea609a03b 100644 --- a/roles/web-app-nextcloud/templates/compose.yml.j2 +++ b/roles/web-app-nextcloud/templates/compose.yml.j2 @@ -9,7 +9,7 @@ {{ lookup('compose_restart') }} {{ lookup('container_ports', ['nextcloud', 'http', DOCKER_BIND_HOST]) | indent(4) }} {{ lookup('container_volumes', service_name) | indent(4) }} - {{ lookup('container_healthcheck', service_name, samples=(groups[application_id] | default([]) | length) if DEPLOYMENT_MODE == 'swarm' else 1) | indent(4) }} + {{ lookup('container_healthcheck', service_name, samples=(groups[application_id] | default([]) | length) if IS_SWARM_MODE else 1) | indent(4) }} {{ lookup('container_networks') | indent(4) }} {{ lookup('container_extra_hosts', extra_hosts=( ['host.docker.internal:host-gateway'] if NEXTCLOUD_HPB_NETWORK_MODE == 'host' else [] @@ -23,7 +23,7 @@ {{ lookup('template', 'roles/sys-svc-container/templates/build.yml.j2') | indent(4) }} {{ lookup('container_volumes', service_name) | indent(4) }} - {% if DEPLOYMENT_MODE == 'swarm' %} + {% if IS_SWARM_MODE %} environment: TASK_SLOT: "{% raw %}{{.Task.Slot}}{% endraw %}" {% endif %} diff --git a/roles/web-app-nextcloud/templates/config/memcache.config.php.j2 b/roles/web-app-nextcloud/templates/config/memcache.config.php.j2 index 2a5231bfe8..2e81c4695b 100644 --- a/roles/web-app-nextcloud/templates/config/memcache.config.php.j2 +++ b/roles/web-app-nextcloud/templates/config/memcache.config.php.j2 @@ -1,5 +1,5 @@ '\\OC\\Memcache\\APCu', ]; diff --git a/roles/web-app-nextcloud/vars/main.yml b/roles/web-app-nextcloud/vars/main.yml index f0cdb2c8c5..42722fc126 100644 --- a/roles/web-app-nextcloud/vars/main.yml +++ b/roles/web-app-nextcloud/vars/main.yml @@ -69,7 +69,7 @@ NEXTCLOUD_PROXY_EXCLUDED_INTERNAL_HOSTS: NEXTCLOUD_PROXY_SERVICE: "proxy" NEXTCLOUD_PROXY_CONTAINER: "{{ lookup('config', application_id, 'services.' ~ NEXTCLOUD_PROXY_SERVICE ~ '.name') }}" -NEXTCLOUD_PROXY_DNS_NAME: "{{ (entity_name ~ '_' ~ NEXTCLOUD_PROXY_SERVICE) if DEPLOYMENT_MODE == 'swarm' else NEXTCLOUD_PROXY_CONTAINER }}" +NEXTCLOUD_PROXY_DNS_NAME: "{{ (entity_name ~ '_' ~ NEXTCLOUD_PROXY_SERVICE) if IS_SWARM_MODE else NEXTCLOUD_PROXY_CONTAINER }}" NEXTCLOUD_MCP_ENABLED: "{{ lookup('config', application_id, 'services.context_agent.enabled') | bool }}" NEXTCLOUD_MCP_PATH: "{{ lookup('config', application_id, 'mcp.adapter.upstream_path') }}" @@ -102,7 +102,7 @@ NEXTCLOUD_CONTEXT_AGENT_CONTAINER: "{{ lookup('config', application_id, 'service NEXTCLOUD_CONTEXT_AGENT_VERSION: "{{ lookup('config', application_id, 'services.' ~ NEXTCLOUD_CONTEXT_AGENT_SERVICE ~ '.version') }}" NEXTCLOUD_CONTEXT_AGENT_PORT: "{{ lookup('config', application_id, 'services.' ~ NEXTCLOUD_CONTEXT_AGENT_SERVICE ~ '.ports.internal.http') }}" NEXTCLOUD_CONTEXT_AGENT_SECRET: "{{ lookup('config', application_id, 'secrets.credentials.context_agent_app_secret') }}" -NEXTCLOUD_CONTEXT_AGENT_DNS_NAME: "{{ (entity_name ~ '_' ~ NEXTCLOUD_CONTEXT_AGENT_SERVICE) if DEPLOYMENT_MODE == 'swarm' else NEXTCLOUD_CONTEXT_AGENT_CONTAINER }}" +NEXTCLOUD_CONTEXT_AGENT_DNS_NAME: "{{ (entity_name ~ '_' ~ NEXTCLOUD_CONTEXT_AGENT_SERVICE) if IS_SWARM_MODE else NEXTCLOUD_CONTEXT_AGENT_CONTAINER }}" NEXTCLOUD_CONTEXT_AGENT_DAEMON: "manual_install" NEXTCLOUD_CONTEXT_AGENT_NEXTCLOUD_URL: "http://{{ NEXTCLOUD_PROXY_DNS_NAME }}:{{ container_port }}" NEXTCLOUD_CONTEXT_AGENT_ROUTES: diff --git a/roles/web-app-odoo/tasks/01_manager_ops.yml b/roles/web-app-odoo/tasks/01_manager_ops.yml index 3525ba9311..6bd839874e 100644 --- a/roles/web-app-odoo/tasks/01_manager_ops.yml +++ b/roles/web-app-odoo/tasks/01_manager_ops.yml @@ -75,7 +75,7 @@ changed_when: true when: - (ODOO_OIDC_ENABLED | bool) or (ODOO_LDAP_ENABLED | bool) - - DEPLOYMENT_MODE == 'compose' + - IS_COMPOSE_MODE - name: "♻️ Restart Odoo to load SQL-provisioned config (swarm)" ansible.builtin.command: "container service update --force {{ lookup('container_service', application_id, ODOO_SERVICE) }}" @@ -83,7 +83,7 @@ timeout: "{{ lookup('timeout', 600) | int }}" when: - (ODOO_OIDC_ENABLED | bool) or (ODOO_LDAP_ENABLED | bool) - - DEPLOYMENT_MODE == 'swarm' + - IS_SWARM_MODE - name: "🔍 Re-resolve Odoo hosting node + container id after the provisioning restart" ansible.builtin.include_tasks: "{{ lookup('path_absolute', 'roles/sys-svc-compose/tasks/utils/swarm/resolve_host_cid.yml') }}" diff --git a/roles/web-app-odoo/tasks/02_init_database/bootstrap_schema.yml b/roles/web-app-odoo/tasks/02_init_database/bootstrap_schema.yml index 5ac26cd87b..373e18563e 100644 --- a/roles/web-app-odoo/tasks/02_init_database/bootstrap_schema.yml +++ b/roles/web-app-odoo/tasks/02_init_database/bootstrap_schema.yml @@ -15,13 +15,13 @@ - name: "🔄 Restart Odoo container after initialization (compose)" ansible.builtin.command: container restart {{ ODOO_CONTAINER }} changed_when: true - when: DEPLOYMENT_MODE == 'compose' + when: IS_COMPOSE_MODE - name: "🔄 Restart Odoo service after initialization (swarm)" ansible.builtin.command: "container service update --force {{ lookup('container_service', application_id, ODOO_SERVICE) }}" changed_when: true timeout: "{{ lookup('timeout', 600) | int }}" - when: DEPLOYMENT_MODE == 'swarm' + when: IS_SWARM_MODE - name: "🔍 Re-resolve Odoo hosting node + container id after the init restart" ansible.builtin.include_tasks: "{{ lookup('path_absolute', 'roles/sys-svc-compose/tasks/utils/swarm/resolve_host_cid.yml') }}" diff --git a/roles/web-app-odoo/tasks/03_install_modules.yml b/roles/web-app-odoo/tasks/03_install_modules.yml index bd6b1f0a03..d8bebf3ffc 100644 --- a/roles/web-app-odoo/tasks/03_install_modules.yml +++ b/roles/web-app-odoo/tasks/03_install_modules.yml @@ -31,11 +31,11 @@ - name: "♻️ Restart Odoo so the entrypoint runs `-u all` as the sole DB actor (compose)" ansible.builtin.command: container restart {{ ODOO_CONTAINER }} changed_when: true - when: DEPLOYMENT_MODE == 'compose' + when: IS_COMPOSE_MODE - name: "♻️ Restart Odoo so the entrypoint runs `-u all` as the sole DB actor (swarm)" ansible.builtin.include_tasks: 03_install_modules/swarm_drain_restart.yml - when: DEPLOYMENT_MODE == 'swarm' + when: IS_SWARM_MODE - name: "🔍 Re-resolve Odoo hosting node + container id after the update restart" ansible.builtin.include_tasks: "{{ lookup('path_absolute', 'roles/sys-svc-compose/tasks/utils/swarm/resolve_host_cid.yml') }}" diff --git a/roles/web-app-openclaw/tasks/00_core.yml b/roles/web-app-openclaw/tasks/00_core.yml index 6f2d5001cc..e5e3202107 100644 --- a/roles/web-app-openclaw/tasks/00_core.yml +++ b/roles/web-app-openclaw/tasks/00_core.yml @@ -23,6 +23,6 @@ vars: assert_isolated_container: "{{ OPENCLAW_CONTAINER }}" when: - - DEPLOYMENT_MODE == 'compose' + - IS_COMPOSE_MODE - "'svc-ai-robot' not in group_names" - lookup('config', application_id, 'services.kata.enabled') | bool diff --git a/roles/web-app-openproject/tasks/02_settings.yml b/roles/web-app-openproject/tasks/02_settings.yml index 50a30dfd6e..c2e55f667a 100644 --- a/roles/web-app-openproject/tasks/02_settings.yml +++ b/roles/web-app-openproject/tasks/02_settings.yml @@ -8,7 +8,7 @@ delay: 5 until: openproject_web_state.stdout.strip() == "running" changed_when: false - when: DEPLOYMENT_MODE == 'compose' + when: IS_COMPOSE_MODE - name: ⏳ Wait until OpenProject web service converged (swarm) ansible.builtin.include_tasks: "{{ lookup('path_absolute', 'roles/sys-svc-compose/tasks/utils/swarm/wait_converged.yml') }}" @@ -44,7 +44,7 @@ delay: 5 until: openproject_web_state_after_migrate.stdout.strip() == "running" changed_when: false - when: DEPLOYMENT_MODE == 'compose' + when: IS_COMPOSE_MODE - name: ⏳ Wait until OpenProject web service converged (after migrations, swarm) ansible.builtin.include_tasks: "{{ lookup('path_absolute', 'roles/sys-svc-compose/tasks/utils/swarm/wait_converged.yml') }}" diff --git a/roles/web-app-openwebui/tasks/utils/refresh_model_grants.yml b/roles/web-app-openwebui/tasks/utils/refresh_model_grants.yml index 0d5f36b977..a2e556300e 100644 --- a/roles/web-app-openwebui/tasks/utils/refresh_model_grants.yml +++ b/roles/web-app-openwebui/tasks/utils/refresh_model_grants.yml @@ -3,7 +3,7 @@ ansible.builtin.command: argv: >- {{ ['container', 'service', 'ls', '-q', '--filter', 'name=' ~ lookup('container_service', application_id, entity_name)] - if DEPLOYMENT_MODE == 'swarm' + if IS_SWARM_MODE else ['container', 'ps', '-q', '--filter', 'status=running', '--filter', 'name=^' ~ OPENWEBUI_CONTAINER ~ '$'] }} register: openwebui_running changed_when: false diff --git a/roles/web-app-prometheus/meta/volumes.yml b/roles/web-app-prometheus/meta/volumes.yml index 737e013464..b64eb9283d 100644 --- a/roles/web-app-prometheus/meta/volumes.yml +++ b/roles/web-app-prometheus/meta/volumes.yml @@ -88,7 +88,7 @@ host_dev_disk: mounts: - service: cadvisor target: /dev/disk - when: "{{ DEPLOYMENT_MODE == 'compose' }}" + when: "{{ IS_COMPOSE_MODE }}" host_proc: type: bind diff --git a/roles/web-app-prometheus/templates/compose.yml.j2 b/roles/web-app-prometheus/templates/compose.yml.j2 index cb38fb558f..d07bf15600 100644 --- a/roles/web-app-prometheus/templates/compose.yml.j2 +++ b/roles/web-app-prometheus/templates/compose.yml.j2 @@ -45,7 +45,7 @@ {% include 'roles/sys-svc-container/templates/base.yml.j2' %} {{ lookup('container_image', application_id, 'cadvisor') }} {{ lookup('compose_only', 'container_name', CADVISOR_CONTAINER) }} - {% if DEPLOYMENT_MODE == 'compose' %} + {% if IS_COMPOSE_MODE %} privileged: true devices: - /dev/kmsg @@ -58,7 +58,7 @@ {% include 'roles/sys-svc-container/templates/base.yml.j2' %} {{ lookup('container_image', application_id, 'node-exporter') }} {{ lookup('compose_only', 'container_name', NODE_EXPORTER_CONTAINER) }} - {% if DEPLOYMENT_MODE == 'compose' %} + {% if IS_COMPOSE_MODE %} # nocheck: network-mode-host-without-swarm-gate network_mode: host pid: host diff --git a/roles/web-app-seaweedfs/templates/service.yml.j2 b/roles/web-app-seaweedfs/templates/service.yml.j2 index 1b4a8a7358..29d4b2d6ce 100644 --- a/roles/web-app-seaweedfs/templates/service.yml.j2 +++ b/roles/web-app-seaweedfs/templates/service.yml.j2 @@ -20,7 +20,7 @@ {%- endset -%} {{ _snippet | indent(indent, true) }} {%- endmacro %} -{% if DEPLOYMENT_MODE == 'compose' %} +{% if IS_COMPOSE_MODE %} {{ include_resource_for('seaweedfs') }} {% endif %} {% set service_name = 'seaweedfs' %} diff --git a/roles/web-app-snipe-it/tasks/01_install.yml b/roles/web-app-snipe-it/tasks/01_install.yml index e7dad621e8..bdb6a90828 100644 --- a/roles/web-app-snipe-it/tasks/01_install.yml +++ b/roles/web-app-snipe-it/tasks/01_install.yml @@ -2,7 +2,7 @@ - name: ⏳ Wait until application container is up ansible.builtin.shell: >- container ps - --filter {{ ('label=com.docker.swarm.service.name=' ~ lookup('container_service', application_id, SNIPE_IT_SERVICE)) if DEPLOYMENT_MODE == 'swarm' else ('name=^' + --filter {{ ('label=com.docker.swarm.service.name=' ~ lookup('container_service', application_id, SNIPE_IT_SERVICE)) if IS_SWARM_MODE else ('name=^' ~ lookup('container_service', application_id, SNIPE_IT_SERVICE) ~ '$') }} --format '{% raw %}{{.ID}}{% endraw %}' register: snipeit_app_id diff --git a/tests/lint/ansible/jinja/test_compose_template_file_bind_mount_swarm_fragile.py b/tests/lint/ansible/jinja/test_compose_template_file_bind_mount_swarm_fragile.py index 6195c3f06b..04fa8cc5e0 100644 --- a/tests/lint/ansible/jinja/test_compose_template_file_bind_mount_swarm_fragile.py +++ b/tests/lint/ansible/jinja/test_compose_template_file_bind_mount_swarm_fragile.py @@ -38,12 +38,10 @@ _ELIF = re.compile(r"\{%\s*elif\s+(?P.+?)\s*%\}") _ELSE = re.compile(r"\{%\s*else\s*%\}") _ENDIF = re.compile(r"\{%\s*endif\s*%\}") _COMPOSE_ONLY_GATE = re.compile( - r"DEPLOYMENT_MODE\s*!=\s*['\"]swarm['\"]" - r"|DEPLOYMENT_MODE\s*==\s*['\"]compose['\"]" + r"not\s+IS_SWARM_MODE|IS_COMPOSE_MODE" ) _SWARM_ONLY_GATE = re.compile( - r"DEPLOYMENT_MODE\s*==\s*['\"]swarm['\"]" - r"|DEPLOYMENT_MODE\s*!=\s*['\"]compose['\"]" + r"(? bool: def _is_inside_compose_only_gate(lines: list[str], target_idx: int) -> bool: - """True iff lines[target_idx] sits under a `DEPLOYMENT_MODE == 'compose'` gate.""" + """True iff lines[target_idx] sits under a `IS_COMPOSE_MODE` gate.""" stack: list[tuple[str, bool]] = [] for i, raw in enumerate(lines): if i == target_idx: diff --git a/tests/lint/ansible/jinja/test_compose_template_no_unguarded_depends_on_condition.py b/tests/lint/ansible/jinja/test_compose_template_no_unguarded_depends_on_condition.py index 5619733bf0..7f23c395b1 100644 --- a/tests/lint/ansible/jinja/test_compose_template_no_unguarded_depends_on_condition.py +++ b/tests/lint/ansible/jinja/test_compose_template_no_unguarded_depends_on_condition.py @@ -1,7 +1,7 @@ """Flag ``condition: service_healthy`` (and ``service_completed_successfully``) under ``depends_on:`` in ``compose.yml.j2`` templates when the line is NOT inside a -``{% if DEPLOYMENT_MODE == 'compose' %}`` (or equivalent compose-only) +``{% if IS_COMPOSE_MODE %}`` (or equivalent compose-only) Jinja gate. ``docker stack deploy`` accepts only the list form of ``depends_on``; @@ -33,12 +33,10 @@ _ELIF = re.compile(r"\{%\s*elif\s+(?P.+?)\s*%\}") _ELSE = re.compile(r"\{%\s*else\s*%\}") _ENDIF = re.compile(r"\{%\s*endif\s*%\}") _COMPOSE_ONLY_GATE = re.compile( - r"DEPLOYMENT_MODE\s*!=\s*['\"]swarm['\"]" - r"|DEPLOYMENT_MODE\s*==\s*['\"]compose['\"]" + r"not\s+IS_SWARM_MODE|IS_COMPOSE_MODE" ) _SWARM_ONLY_GATE = re.compile( - r"DEPLOYMENT_MODE\s*==\s*['\"]swarm['\"]" - r"|DEPLOYMENT_MODE\s*!=\s*['\"]compose['\"]" + r"(?.+?)\s*%\}") _ELSE = re.compile(r"\{%\s*else\s*%\}") _ENDIF = re.compile(r"\{%\s*endif\s*%\}") _COMPOSE_ONLY_GATE = re.compile( - r"DEPLOYMENT_MODE\s*!=\s*['\"]swarm['\"]" - r"|DEPLOYMENT_MODE\s*==\s*['\"]compose['\"]" + r"not\s+IS_SWARM_MODE|IS_COMPOSE_MODE" ) _SWARM_ONLY_GATE = re.compile( - r"DEPLOYMENT_MODE\s*==\s*['\"]swarm['\"]" - r"|DEPLOYMENT_MODE\s*!=\s*['\"]compose['\"]" + r"(?.+?)\s*%\}") _ELIF = re.compile(r"\{%\s*elif\s+(?P.+?)\s*%\}") _ELSE = re.compile(r"\{%\s*else\s*%\}") _ENDIF = re.compile(r"\{%\s*endif\s*%\}") -_COMPOSE_ONLY_GATE = re.compile( - r"DEPLOYMENT_MODE\s*!=\s*['\"]swarm['\"]" - r"|DEPLOYMENT_MODE\s*==\s*['\"]compose['\"]" -) -_SWARM_ONLY_GATE = re.compile( - r"DEPLOYMENT_MODE\s*==\s*['\"]swarm['\"]" - r"|DEPLOYMENT_MODE\s*!=\s*['\"]compose['\"]" -) +_COMPOSE_ONLY_GATE = re.compile(r"not\s+IS_SWARM_MODE|IS_COMPOSE_MODE") +_SWARM_ONLY_GATE = re.compile(r"(? bool: @@ -93,7 +87,7 @@ class TestComposeTemplateNoUnguardedProfiles(unittest.TestCase): "without a compose-only gate. swarm silently ignores " "profiles, so a profile-gated one-shot bootstrap deploys " "as a regular replicated service and restart-loops.\n\n" - "Fix: wrap in `{% if DEPLOYMENT_MODE == 'compose' %}` and " + "Fix: wrap in `{% if IS_COMPOSE_MODE %}` and " "adjust the swarm path so the bootstrap is either deployed " "as a true one-shot (restart_policy: condition: none) or " "tail-its-logs-driven. Mark with " diff --git a/tests/lint/ansible/jinja/test_compose_template_uses_depends_on_lookup.py b/tests/lint/ansible/jinja/test_compose_template_uses_depends_on_lookup.py index c5cd976ef2..32bb24d35b 100644 --- a/tests/lint/ansible/jinja/test_compose_template_uses_depends_on_lookup.py +++ b/tests/lint/ansible/jinja/test_compose_template_uses_depends_on_lookup.py @@ -8,7 +8,7 @@ this codebase is the ``depends_on`` lookup: The lookup emits the map form for compose (with conditions) and the list form for swarm. Hand-writing the per-mode gate -(``{% if DEPLOYMENT_MODE == 'swarm' %} … {% else %} … {% endif %}``) +(``{% if IS_SWARM_MODE %} … {% else %} … {% endif %}``) is the pattern this rule eliminates - it is repetitive, easy to forget, and the lookup is the single source of truth for the compose/swarm dependency shape. diff --git a/tests/lint/ansible/shell/container/test_address_never_quoted.py b/tests/lint/ansible/shell/container/test_address_never_quoted.py index 320bda4a65..7d48675f6f 100644 --- a/tests/lint/ansible/shell/container/test_address_never_quoted.py +++ b/tests/lint/ansible/shell/container/test_address_never_quoted.py @@ -16,7 +16,7 @@ Per-line opt-out Add ``# nocheck: container-address-quote`` on the same line as the ``| quote`` usage or on the immediately preceding non-empty line. Reserved for sites that provably never see the swarm fragment -(``DEPLOYMENT_MODE == 'compose'``-gated tasks, roles pinned via +(``IS_COMPOSE_MODE``-gated tasks, roles pinned via ``compose_mode_force``) or consumers that re-evaluate the argument themselves (e.g. ``set_postgres_superuser_password.sh``). """ diff --git a/tests/lint/ansible/shell/test_no_compose_chdir_in_shell_tasks.py b/tests/lint/ansible/shell/test_no_compose_chdir_in_shell_tasks.py index 8917d85906..1f0e35f0ce 100644 --- a/tests/lint/ansible/shell/test_no_compose_chdir_in_shell_tasks.py +++ b/tests/lint/ansible/shell/test_no_compose_chdir_in_shell_tasks.py @@ -82,13 +82,13 @@ class TestNoComposeChdirInShellTasks(unittest.TestCase): " - `compose restart` -> `container service update --force " "{{ lookup('container_service', application_id, '') }}` " "for swarm + `compose restart` for compose (split with " - "`when: DEPLOYMENT_MODE == 'compose'` / `== 'swarm'` blocks)\n" + "`when: IS_COMPOSE_MODE` / `== 'swarm'` blocks)\n" " - one-shot bootstrap via `compose run --profile X` -> deploy " "the bootstrap service unconditionally in compose.yml.j2 and, " "in swarm, tail `container service logs " "{{ lookup('container_service', application_id, '') }}` " "for the result. The compose path keeps the profile + the " - "compose-run task (gated on `when: DEPLOYMENT_MODE == 'compose'`).\n\n" + "compose-run task (gated on `when: IS_COMPOSE_MODE`).\n\n" "Mark with `# nocheck: compose-chdir-in-task` only when the role " "is intentionally compose-only by design.\n\n" f"Offending lines:\n{formatted}" diff --git a/tests/lint/ansible/shell/test_no_compose_verb_in_shell_tasks.py b/tests/lint/ansible/shell/test_no_compose_verb_in_shell_tasks.py index 846f4c575c..bccc59a9ef 100644 --- a/tests/lint/ansible/shell/test_no_compose_verb_in_shell_tasks.py +++ b/tests/lint/ansible/shell/test_no_compose_verb_in_shell_tasks.py @@ -93,7 +93,7 @@ class TestNoComposeVerbInShellTasks(unittest.TestCase): "Fix: replace with `container ` via the wrapper and use " "`lookup('container_address', ...)` / `lookup('container_service', ...)` " "for the target. If the call is legitimately compose-only, wrap it " - "in a block gated by `when: DEPLOYMENT_MODE == 'compose'` and add a " + "in a block gated by `when: IS_COMPOSE_MODE` and add a " "swarm-equivalent alongside, OR mark with " "`# nocheck: compose-verb-in-task` if the role itself is " "compose-only by design.\n\n" diff --git a/tests/lint/ansible/shell/test_no_docker_compose_raw_call.py b/tests/lint/ansible/shell/test_no_docker_compose_raw_call.py index 0bb85e2c29..34c1330218 100644 --- a/tests/lint/ansible/shell/test_no_docker_compose_raw_call.py +++ b/tests/lint/ansible/shell/test_no_docker_compose_raw_call.py @@ -65,7 +65,7 @@ class TestNoDockerComposeRawCall(unittest.TestCase): "`container` wrapper for everything else.\n\n" "Fix: replace `docker compose ...` with " "`{{ BIN_COMPOSE }} ...` and gate behind " - "`when: DEPLOYMENT_MODE == 'compose'` because compose verbs " + "`when: IS_COMPOSE_MODE` because compose verbs " "don't work under `docker stack deploy`. For inspect/exec " "use `container ` via the wrapper. Mark with " "`# nocheck: docker-compose-raw-call` only for compose-only " diff --git a/tests/lint/ansible/structure/test_no_oversized_ansible_block.py b/tests/lint/ansible/structure/test_no_oversized_ansible_block.py index 2db2d08d30..24a052829a 100644 --- a/tests/lint/ansible/structure/test_no_oversized_ansible_block.py +++ b/tests/lint/ansible/structure/test_no_oversized_ansible_block.py @@ -6,10 +6,10 @@ and tempt callers to express conditions / delegate_to / vars on the outer wrapper that semantically belong to a single grouped concern. The convention is: ≤ 3 direct children, otherwise extract the body into its own ``include_tasks:`` sub-file. If the include is gated by -``when: DEPLOYMENT_MODE == "compose"`` (or another compose-only guard), +``when: IS_COMPOSE_MODE`` (or another compose-only guard), the sub-file MAY carry the file-header marker - # include-gated: when: DEPLOYMENT_MODE == "compose" + # include-gated: when: IS_COMPOSE_MODE so the swarm-compat lints (``compose-chdir-in-task`` / ``compose-verb-in-task``) treat the file as exempt — see @@ -125,10 +125,10 @@ class TestNoOversizedAnsibleBlock(unittest.TestCase): "stays scannable.\n\n" "Example refactor:\n" " - name: ''\n" - " when: DEPLOYMENT_MODE != 'swarm'\n" + " when: not IS_SWARM_MODE\n" " include_tasks: _.yml\n\n" "If the sub-file is when-gated, mark it with the header\n" - ' # include-gated: when: DEPLOYMENT_MODE != "swarm"\n' + ' # include-gated: when: not IS_SWARM_MODE\n' "(see utils/annotations/task_gate.py) so the swarm-compat " f"lints exempt it.\n\nOffenders:\n{formatted}" ) diff --git a/tests/lint/ansible/variables/test_deployment_mode_booleans.py b/tests/lint/ansible/variables/test_deployment_mode_booleans.py new file mode 100644 index 0000000000..c28c6718e4 --- /dev/null +++ b/tests/lint/ansible/variables/test_deployment_mode_booleans.py @@ -0,0 +1,78 @@ +"""The deployment mode is asked by name, not compared to a string. + +``IS_COMPOSE_MODE`` and ``IS_SWARM_MODE`` say what the comparison meant, and +they say it once. Spelling the mode out against a quoted literal writes the +same predicate in a hundred places: a third mode, a renamed value or an +inverted default then has to be chased through all of them. + +Both are real booleans under this Ansible, so a template writes +``{% if IS_SWARM_MODE %}`` without a ``| bool``. + +Only ``group_vars/all/18_swarm.yml`` may compare, because that is where the +two are defined. +""" + +from __future__ import annotations + +import re +import unittest +from pathlib import Path + +from utils.cache.files import iter_non_ignored_files, read_text + +from . import PROJECT_ROOT + +DEFINITION = Path("group_vars/all/18_swarm.yml") +SUFFIXES = {".yml", ".yaml", ".j2", ".py", ".sh", ".tmpl"} +COMPARISON = re.compile(r"DEPLOYMENT_MODE\s*[!=]=\s*['\"](?Pcompose|swarm)['\"]") +REPLACEMENT = { + ("==", "compose"): "IS_COMPOSE_MODE", + ("==", "swarm"): "IS_SWARM_MODE", + ("!=", "compose"): "not IS_COMPOSE_MODE", + ("!=", "swarm"): "not IS_SWARM_MODE", +} + + +def _offenders() -> list[str]: + found: list[str] = [] + for raw in sorted(iter_non_ignored_files()): + path = Path(raw) + if path.suffix not in SUFFIXES: + continue + relative = path.relative_to(PROJECT_ROOT) + if relative == DEFINITION: + continue + try: + lines = read_text(str(path)).splitlines() + except (OSError, UnicodeDecodeError): + continue + for number, line in enumerate(lines, 1): + match = COMPARISON.search(line) + if match: + found.append(f"{relative}:{number}: {match.group(0)}") + return found + + +class TestDeploymentModeBooleans(unittest.TestCase): + def test_no_file_compares_the_mode_to_a_string(self) -> None: + offenders = _offenders() + + self.assertEqual( + offenders, + [], + f"{len(offenders)} comparison(s) spell out the deployment mode. Use " + f"the named boolean instead:\n" + + "\n".join(f" {k[0]} '{k[1]}' -> {v}" for k, v in REPLACEMENT.items()) + + "\n\n" + + "\n".join(offenders[:20]), + ) + + def test_the_definition_still_declares_both(self) -> None: + declared = read_text(str(PROJECT_ROOT / DEFINITION)) + + for name in ("IS_COMPOSE_MODE", "IS_SWARM_MODE"): + self.assertIn(f"{name}:", declared, f"{DEFINITION} no longer defines {name}") + + +if __name__ == "__main__": + unittest.main() diff --git a/tests/lint/ansible/variables/test_no_deployment_mode_negation.py b/tests/lint/ansible/variables/test_no_deployment_mode_negation.py index d6559547d7..35c688a775 100644 --- a/tests/lint/ansible/variables/test_no_deployment_mode_negation.py +++ b/tests/lint/ansible/variables/test_no_deployment_mode_negation.py @@ -58,7 +58,7 @@ class TestNoDeploymentModeNegation(unittest.TestCase): self.fail( "Found negated `DEPLOYMENT_MODE != ...` gates. DEPLOYMENT_MODE is " "binary (swarm / compose), so use the positive form for " - "readability: `DEPLOYMENT_MODE == 'compose'` instead of " + "readability: `IS_COMPOSE_MODE` instead of " "`!= 'swarm'` (and `== 'swarm'` instead of `!= 'compose'`).\n\n" "Mark with `# nocheck: deployment-mode-negation` only when the " "negation is genuinely required.\n\n" diff --git a/tests/unit/python/plugins/lookup/test_backup_volume.py b/tests/unit/python/plugins/lookup/test_backup_volume.py index 7f2b59b5b3..3c3516fe0c 100644 --- a/tests/unit/python/plugins/lookup/test_backup_volume.py +++ b/tests/unit/python/plugins/lookup/test_backup_volume.py @@ -86,6 +86,8 @@ class TestSwarmNfsExclusion(unittest.TestCase): SWARM_NFS: ClassVar[dict] = { "DEPLOYMENT_MODE": "swarm", + "IS_COMPOSE_MODE": False, + "IS_SWARM_MODE": True, "storage": {"backend": "nfs"}, "groups": {"svc-bkp-nfs-2-local": ["nfs-server"]}, } @@ -212,6 +214,8 @@ class TestSwarmNfsExclusion(unittest.TestCase): apps, variables={ "DEPLOYMENT_MODE": "compose", + "IS_COMPOSE_MODE": True, + "IS_SWARM_MODE": False, "storage": {"backend": "local"}, }, ), diff --git a/tests/unit/python/plugins/lookup/test_compose_networks.py b/tests/unit/python/plugins/lookup/test_compose_networks.py index c6b6708db3..2497d3a30e 100644 --- a/tests/unit/python/plugins/lookup/test_compose_networks.py +++ b/tests/unit/python/plugins/lookup/test_compose_networks.py @@ -49,6 +49,8 @@ class TestComposeNetworksLookup(unittest.TestCase): vars_ = { "application_id": "web-app-baserow", "DEPLOYMENT_MODE": "swarm", + "IS_COMPOSE_MODE": False, + "IS_SWARM_MODE": True, "swarm": {"network": {"encryption": False}}, } lm = _make_lookup(vars_) @@ -78,6 +80,8 @@ class TestComposeNetworksLookup(unittest.TestCase): vars_ = { "application_id": "web-app-x", "DEPLOYMENT_MODE": "swarm", + "IS_COMPOSE_MODE": False, + "IS_SWARM_MODE": True, } lm = _make_lookup(vars_) @@ -103,6 +107,8 @@ class TestComposeNetworksLookup(unittest.TestCase): vars_ = { "application_id": "web-app-x", "DEPLOYMENT_MODE": "swarm", + "IS_COMPOSE_MODE": False, + "IS_SWARM_MODE": True, } lm = _make_lookup(vars_) diff --git a/tests/unit/python/plugins/lookup/test_compose_replicas.py b/tests/unit/python/plugins/lookup/test_compose_replicas.py index 0941ad3f83..b0054fe2e8 100644 --- a/tests/unit/python/plugins/lookup/test_compose_replicas.py +++ b/tests/unit/python/plugins/lookup/test_compose_replicas.py @@ -53,6 +53,8 @@ class TestComposeReplicasLookup(unittest.TestCase): def test_compose_mode_no_arg_emits_empty(self): vars_ = { "DEPLOYMENT_MODE": "compose", + "IS_COMPOSE_MODE": True, + "IS_SWARM_MODE": False, "application_id": "web-app-x", "groups": {"web-app-x": ["h1", "h2", "h3"]}, } @@ -75,6 +77,8 @@ class TestComposeReplicasLookup(unittest.TestCase): def test_swarm_mode_default_uses_group_length(self): vars_ = { "DEPLOYMENT_MODE": "swarm", + "IS_COMPOSE_MODE": False, + "IS_SWARM_MODE": True, "application_id": "web-app-x", "groups": {"web-app-x": ["mgr-01", "wrk-01", "wrk-02"]}, } @@ -84,6 +88,8 @@ class TestComposeReplicasLookup(unittest.TestCase): def test_swarm_mode_single_host_yields_one(self): vars_ = { "DEPLOYMENT_MODE": "swarm", + "IS_COMPOSE_MODE": False, + "IS_SWARM_MODE": True, "application_id": "web-app-x", "groups": {"web-app-x": ["h1"]}, } @@ -93,6 +99,8 @@ class TestComposeReplicasLookup(unittest.TestCase): def test_swarm_mode_empty_group_falls_back_to_one(self): vars_ = { "DEPLOYMENT_MODE": "swarm", + "IS_COMPOSE_MODE": False, + "IS_SWARM_MODE": True, "application_id": "web-app-x", "groups": {"web-app-x": []}, } @@ -102,6 +110,8 @@ class TestComposeReplicasLookup(unittest.TestCase): def test_swarm_mode_missing_group_falls_back_to_one(self): vars_ = { "DEPLOYMENT_MODE": "swarm", + "IS_COMPOSE_MODE": False, + "IS_SWARM_MODE": True, "application_id": "web-app-x", "groups": {}, } @@ -111,6 +121,8 @@ class TestComposeReplicasLookup(unittest.TestCase): def test_swarm_mode_explicit_override(self): vars_ = { "DEPLOYMENT_MODE": "swarm", + "IS_COMPOSE_MODE": False, + "IS_SWARM_MODE": True, "application_id": "web-app-x", "groups": {"web-app-x": ["h1", "h2", "h3"]}, } @@ -151,6 +163,8 @@ class TestComposeReplicasLookup(unittest.TestCase): def test_none_terms_treated_as_no_args(self): vars_ = { "DEPLOYMENT_MODE": "swarm", + "IS_COMPOSE_MODE": False, + "IS_SWARM_MODE": True, "application_id": "web-app-x", "groups": {"web-app-x": ["a", "b"]}, } diff --git a/tests/unit/python/plugins/lookup/test_compose_restart.py b/tests/unit/python/plugins/lookup/test_compose_restart.py index 0247608309..9b2a30bee8 100644 --- a/tests/unit/python/plugins/lookup/test_compose_restart.py +++ b/tests/unit/python/plugins/lookup/test_compose_restart.py @@ -122,6 +122,8 @@ class TestComposeRestartLookup(unittest.TestCase): explicitly when the Jinja-scope override matters.""" vars_ = { "DEPLOYMENT_MODE": "compose", + "IS_COMPOSE_MODE": True, + "IS_SWARM_MODE": False, "docker_restart_policy": "no", "DOCKER_RESTART_POLICY": "always", } diff --git a/tests/unit/python/plugins/lookup/test_compose_volumes.py b/tests/unit/python/plugins/lookup/test_compose_volumes.py index 069f25641a..2ced91e45e 100644 --- a/tests/unit/python/plugins/lookup/test_compose_volumes.py +++ b/tests/unit/python/plugins/lookup/test_compose_volumes.py @@ -42,6 +42,8 @@ def _vars(**extra): base = { "application_id": "web-app-x", "DEPLOYMENT_MODE": "compose", + "IS_COMPOSE_MODE": True, + "IS_SWARM_MODE": False, "DIR_VAR_LIB": _DIR_VAR_LIB, } base.update(extra) diff --git a/tests/unit/python/plugins/lookup/test_container_address.py b/tests/unit/python/plugins/lookup/test_container_address.py index fd4cebe408..ae6d8734ed 100644 --- a/tests/unit/python/plugins/lookup/test_container_address.py +++ b/tests/unit/python/plugins/lookup/test_container_address.py @@ -89,6 +89,8 @@ class TestContainerExecAddrLookup(unittest.TestCase): "mattermost", variables={ "DEPLOYMENT_MODE": "swarm", + "IS_COMPOSE_MODE": False, + "IS_SWARM_MODE": True, "BIN_RESOLVE_CONTAINER_ID": "/usr/bin/resolve-container-id", }, ) @@ -114,6 +116,8 @@ class TestContainerExecAddrLookup(unittest.TestCase): "mattermost", variables={ "DEPLOYMENT_MODE": "swarm", + "IS_COMPOSE_MODE": False, + "IS_SWARM_MODE": True, "BIN_RESOLVE_CONTAINER_ID": "/opt/scripts/resolve-id", }, ) diff --git a/tests/unit/python/plugins/lookup/test_container_deploy.py b/tests/unit/python/plugins/lookup/test_container_deploy.py index fcd301ed33..1c3175043e 100644 --- a/tests/unit/python/plugins/lookup/test_container_deploy.py +++ b/tests/unit/python/plugins/lookup/test_container_deploy.py @@ -23,6 +23,8 @@ from . import PROJECT_ROOT SWARM = { "DEPLOYMENT_MODE": "swarm", + "IS_COMPOSE_MODE": False, + "IS_SWARM_MODE": True, "application_id": "web-app-x", "groups": {"web-app-x": ["mgr-01", "wrk-01", "wrk-02"]}, } diff --git a/tests/unit/python/plugins/lookup/test_container_dns.py b/tests/unit/python/plugins/lookup/test_container_dns.py index 5436511b06..ef0eddb448 100644 --- a/tests/unit/python/plugins/lookup/test_container_dns.py +++ b/tests/unit/python/plugins/lookup/test_container_dns.py @@ -42,6 +42,8 @@ def _vars(**overrides): "group_names": ["svc-net-tor"], "networks": _CLEARNET, "DEPLOYMENT_MODE": "compose", + "IS_COMPOSE_MODE": True, + "IS_SWARM_MODE": False, "NETWORK_DOCKER_ADDRESS_POOLS": _POOLS, "NETWORK_PUBLIC_DNS_RESOLVERS": _PUBLIC, } diff --git a/tests/unit/python/plugins/lookup/test_container_extra_hosts.py b/tests/unit/python/plugins/lookup/test_container_extra_hosts.py index 955349fc08..f569f139fa 100644 --- a/tests/unit/python/plugins/lookup/test_container_extra_hosts.py +++ b/tests/unit/python/plugins/lookup/test_container_extra_hosts.py @@ -38,6 +38,8 @@ class TestContainerExtraHostsLookup(unittest.TestCase): "_sso_enabled": True, "_provider_domain": ONION, "DEPLOYMENT_MODE": "compose", + "IS_COMPOSE_MODE": True, + "IS_SWARM_MODE": False, } variables.update(overrides) kwargs = {} if extra_hosts is None else {"extra_hosts": extra_hosts} @@ -182,6 +184,8 @@ class TestContainerExtraHostsLookup(unittest.TestCase): "_sso_enabled": True, "_provider_domain": ONION, "DEPLOYMENT_MODE": "compose", + "IS_COMPOSE_MODE": True, + "IS_SWARM_MODE": False, } variables.update(overrides) return self.lookup.run(None, variables=variables, entries_only=True) diff --git a/tests/unit/python/plugins/lookup/test_container_networks.py b/tests/unit/python/plugins/lookup/test_container_networks.py index d407191de1..a44e0f6d0e 100644 --- a/tests/unit/python/plugins/lookup/test_container_networks.py +++ b/tests/unit/python/plugins/lookup/test_container_networks.py @@ -46,6 +46,8 @@ class TestContainerNetworksLookup(unittest.TestCase): vars_ = { "application_id": "web-app-baserow", "DEPLOYMENT_MODE": "compose", + "IS_COMPOSE_MODE": True, + "IS_SWARM_MODE": False, } lm = _make_lookup(vars_) @@ -95,6 +97,8 @@ class TestContainerNetworksLookup(unittest.TestCase): vars_ = { "application_id": "web-app-x", "DEPLOYMENT_MODE": "swarm", + "IS_COMPOSE_MODE": False, + "IS_SWARM_MODE": True, } lm = _make_lookup(vars_) diff --git a/tests/unit/python/plugins/lookup/test_image.py b/tests/unit/python/plugins/lookup/test_image.py index 804d9b9bcc..6940e286d2 100644 --- a/tests/unit/python/plugins/lookup/test_image.py +++ b/tests/unit/python/plugins/lookup/test_image.py @@ -113,6 +113,8 @@ class TestImageLookup(unittest.TestCase): "mattermost", variables={ "DEPLOYMENT_MODE": "swarm", + "IS_COMPOSE_MODE": False, + "IS_SWARM_MODE": True, "swarm": {"registry": {"host": "", "port": 5000}}, }, ) @@ -124,6 +126,8 @@ class TestImageLookup(unittest.TestCase): "mattermost", variables={ "DEPLOYMENT_MODE": "swarm", + "IS_COMPOSE_MODE": False, + "IS_SWARM_MODE": True, "swarm": {"registry": {"host": "registry.example.com", "port": ""}}, }, ) @@ -135,6 +139,8 @@ class TestImageLookup(unittest.TestCase): "mattermost", variables={ "DEPLOYMENT_MODE": "swarm", + "IS_COMPOSE_MODE": False, + "IS_SWARM_MODE": True, "compose_mode_force": "compose", "swarm": { "registry": {"host": "registry.example.com", "port": 5000}, @@ -149,6 +155,8 @@ class TestImageLookup(unittest.TestCase): "mattermost", variables={ "DEPLOYMENT_MODE": "swarm", + "IS_COMPOSE_MODE": False, + "IS_SWARM_MODE": True, "swarm": { "registry": {"host": "registry.example.com", "port": 5000}, }, @@ -226,6 +234,8 @@ class TestImageLookup(unittest.TestCase): "mattermost", variables={ "DEPLOYMENT_MODE": "swarm", + "IS_COMPOSE_MODE": False, + "IS_SWARM_MODE": True, "swarm": { "registry": {"host": "registry.example.com", "port": 5000}, }, @@ -286,6 +296,8 @@ class TestImageLookup(unittest.TestCase): "mattermost", variables={ "DEPLOYMENT_MODE": "swarm", + "IS_COMPOSE_MODE": False, + "IS_SWARM_MODE": True, "swarm": { "registry": { "host": "registry.example.com", @@ -325,6 +337,8 @@ class TestImageLookup(unittest.TestCase): "mattermost", variables={ "DEPLOYMENT_MODE": "swarm", + "IS_COMPOSE_MODE": False, + "IS_SWARM_MODE": True, "swarm": { "registry": { "host": "registry.example.com", @@ -404,6 +418,8 @@ class TestImageLookup(unittest.TestCase): "wb", variables={ "DEPLOYMENT_MODE": "swarm", + "IS_COMPOSE_MODE": False, + "IS_SWARM_MODE": True, "swarm": {"registry": {"host": "mgr", "port": 5000}}, }, applications=apps, diff --git a/tests/unit/python/plugins/lookup/test_proxy_pass.py b/tests/unit/python/plugins/lookup/test_proxy_pass.py index 1d6d14d7a7..50fef86655 100644 --- a/tests/unit/python/plugins/lookup/test_proxy_pass.py +++ b/tests/unit/python/plugins/lookup/test_proxy_pass.py @@ -162,6 +162,8 @@ class TestProxyPassLookup(unittest.TestCase): ["web-app-matrix", "matrix", "http"], variables={ "DEPLOYMENT_MODE": "swarm", + "IS_COMPOSE_MODE": False, + "IS_SWARM_MODE": True, "compose_mode_force": "compose", }, ) @@ -185,6 +187,8 @@ class TestProxyPassLookup(unittest.TestCase): ["web-app-matrix", "matrix", "http"], variables={ "DEPLOYMENT_MODE": "compose", + "IS_COMPOSE_MODE": True, + "IS_SWARM_MODE": False, "compose_mode_force": "compose", }, ) diff --git a/tests/unit/python/plugins/lookup/test_smtp_host.py b/tests/unit/python/plugins/lookup/test_smtp_host.py index 047e26edb0..c95d290b89 100644 --- a/tests/unit/python/plugins/lookup/test_smtp_host.py +++ b/tests/unit/python/plugins/lookup/test_smtp_host.py @@ -71,6 +71,8 @@ class TestSmtpHostLookup(unittest.TestCase): vars_ = { "DOCKER_IN_CONTAINER": True, "DEPLOYMENT_MODE": "swarm", + "IS_COMPOSE_MODE": False, + "IS_SWARM_MODE": True, "group_names": ["svc-swarm-node"], } self.assertEqual(self._resolve(vars_), "127.0.0.1") @@ -79,6 +81,8 @@ class TestSmtpHostLookup(unittest.TestCase): vars_ = { "DOCKER_IN_CONTAINER": True, "DEPLOYMENT_MODE": "swarm", + "IS_COMPOSE_MODE": False, + "IS_SWARM_MODE": True, "group_names": ["svc-nfs-server"], "groups": {"svc-swarm-manager": [MANAGER, "swarm-manager-02"]}, } @@ -88,6 +92,8 @@ class TestSmtpHostLookup(unittest.TestCase): vars_ = { "DOCKER_IN_CONTAINER": True, "DEPLOYMENT_MODE": "swarm", + "IS_COMPOSE_MODE": False, + "IS_SWARM_MODE": True, "group_names": ["svc-nfs-server"], "groups": {"svc-swarm-manager": []}, } @@ -101,6 +107,8 @@ class TestSmtpHostLookup(unittest.TestCase): vars_ = { "DOCKER_IN_CONTAINER": True, "DEPLOYMENT_MODE": "swarm", + "IS_COMPOSE_MODE": False, + "IS_SWARM_MODE": True, "group_names": ["svc-swarm-node"], "groups": {"svc-swarm-manager": [MANAGER]}, } diff --git a/tests/unit/python/roles/sys-svc-container/test_sandbox_runtime.py b/tests/unit/python/roles/sys-svc-container/test_sandbox_runtime.py index 0fdf4fdbc9..b616cc7b2c 100644 --- a/tests/unit/python/roles/sys-svc-container/test_sandbox_runtime.py +++ b/tests/unit/python/roles/sys-svc-container/test_sandbox_runtime.py @@ -69,7 +69,11 @@ class TestSandboxRuntimeRegistration(unittest.TestCase): env.filters["bool"] = _ansible_bool env.filters["to_json"] = json.dumps env.globals["lookup"] = _lookup - raw = env.get_template("daemon.json.j2").render({**BASE, **overrides}) + variables = {**BASE, **overrides} + mode = variables["DEPLOYMENT_MODE"] + variables["IS_COMPOSE_MODE"] = mode == "compose" + variables["IS_SWARM_MODE"] = mode == "swarm" + raw = env.get_template("daemon.json.j2").render(variables) return json.loads(raw) def test_absent_shim_is_never_registered(self): @@ -153,7 +157,11 @@ class TestDaemonStorageDriver(unittest.TestCase): env.filters["bool"] = _ansible_bool env.filters["to_json"] = json.dumps env.globals["lookup"] = _lookup - raw = env.get_template("daemon.json.j2").render({**BASE, **overrides}) + variables = {**BASE, **overrides} + mode = variables["DEPLOYMENT_MODE"] + variables["IS_COMPOSE_MODE"] = mode == "compose" + variables["IS_SWARM_MODE"] = mode == "swarm" + raw = env.get_template("daemon.json.j2").render(variables) return json.loads(raw) def test_docker_in_docker_overrides_the_storage_driver(self): diff --git a/tests/unit/python/roles/web-app-mailu/lookup_plugins/test_mailu_extra_hosts.py b/tests/unit/python/roles/web-app-mailu/lookup_plugins/test_mailu_extra_hosts.py index b0657f94e7..a91d45e1f3 100644 --- a/tests/unit/python/roles/web-app-mailu/lookup_plugins/test_mailu_extra_hosts.py +++ b/tests/unit/python/roles/web-app-mailu/lookup_plugins/test_mailu_extra_hosts.py @@ -46,6 +46,8 @@ class TestMailuExtraHosts(unittest.TestCase): variables = { "application_id": "web-app-mailu", "DEPLOYMENT_MODE": "compose", + "IS_COMPOSE_MODE": True, + "IS_SWARM_MODE": False, "DOCKER_IN_CONTAINER": False, "MAILU_OIDC_ENABLED": False, "MAILU_OIDC_HOST": "auth.example.org", diff --git a/tests/unit/python/utils/annotations/test_task_gate.py b/tests/unit/python/utils/annotations/test_task_gate.py index a21ec4921c..9543ecaadb 100644 --- a/tests/unit/python/utils/annotations/test_task_gate.py +++ b/tests/unit/python/utils/annotations/test_task_gate.py @@ -44,7 +44,7 @@ class TestTaskBlockBounds(unittest.TestCase): compose stop x args: chdir: /opt/compose/x - when: DEPLOYMENT_MODE != 'swarm' + when: not IS_SWARM_MODE """ ) chdir_idx = _line_index(lines, "chdir:") @@ -98,7 +98,7 @@ class TestTaskBlockBounds(unittest.TestCase): compose stop x args: chdir: /opt/compose/x - when: DEPLOYMENT_MODE != 'swarm' + when: not IS_SWARM_MODE """ ) chdir_idx = _line_index(lines, "chdir:") @@ -111,10 +111,10 @@ class TestTaskBlockBounds(unittest.TestCase): lines = _lines( """ - include_tasks: setup.yml - when: DEPLOYMENT_MODE != 'swarm' + when: not IS_SWARM_MODE - import_tasks: run.yml - when: DEPLOYMENT_MODE == 'compose' + when: IS_COMPOSE_MODE """ ) include_idx = _line_index(lines, "include_tasks:") @@ -131,7 +131,7 @@ class TestTaskBlockBounds(unittest.TestCase): block: - name: Inner ansible.builtin.shell: echo hi - when: DEPLOYMENT_MODE != 'swarm' + when: not IS_SWARM_MODE """ ) outer_idx = _line_index(lines, "- name: Outer") @@ -148,7 +148,7 @@ class TestIsTaskComposeOnlyGated(unittest.TestCase): args: chdir: /opt/compose/x executable: /bin/bash - when: DEPLOYMENT_MODE != 'swarm' + when: not IS_SWARM_MODE """ ) chdir_idx = _line_index(lines, "chdir:") @@ -158,7 +158,7 @@ class TestIsTaskComposeOnlyGated(unittest.TestCase): lines = _lines( """ - name: Stop the stack - when: DEPLOYMENT_MODE == 'compose' + when: IS_COMPOSE_MODE ansible.builtin.shell: | compose stop x args: @@ -173,7 +173,7 @@ class TestIsTaskComposeOnlyGated(unittest.TestCase): """ - name: Task shell: compose stop x - when: DEPLOYMENT_MODE != "swarm" + when: not IS_SWARM_MODE """ ) idx = _line_index(lines, "compose stop x") @@ -211,7 +211,7 @@ class TestIsTaskComposeOnlyGated(unittest.TestCase): shell: compose stop x args: chdir: /opt/compose/x - when: DEPLOYMENT_MODE == 'swarm' + when: IS_SWARM_MODE """ ) chdir_idx = _line_index(lines, "chdir:") @@ -222,7 +222,7 @@ class TestIsTaskComposeOnlyGated(unittest.TestCase): """ - name: Gated task shell: compose stop x - when: DEPLOYMENT_MODE != 'swarm' + when: not IS_SWARM_MODE - name: Ungated task shell: compose stop y @@ -240,7 +240,7 @@ class TestIsTaskComposeOnlyGated(unittest.TestCase): shell: compose stop x args: chdir: /opt/compose/x - when: DEPLOYMENT_MODE != 'swarm' and (enable_x | bool) + when: not IS_SWARM_MODE and (enable_x | bool) """ ) chdir_idx = _line_index(lines, "chdir:") @@ -261,7 +261,7 @@ class TestIsTaskComposeOnlyGated(unittest.TestCase): """ --- - name: Some task - when: DEPLOYMENT_MODE != 'swarm' + when: not IS_SWARM_MODE shell: compose stop x """ ) @@ -287,7 +287,7 @@ class TestKnownLimitations(unittest.TestCase): - name: Task shell: compose stop x when: > - DEPLOYMENT_MODE != 'swarm' + not IS_SWARM_MODE """ ) idx = _line_index(lines, "compose stop x") @@ -299,7 +299,7 @@ class TestKnownLimitations(unittest.TestCase): - name: Task shell: compose stop x when: - - DEPLOYMENT_MODE != 'swarm' + - not IS_SWARM_MODE - enable_x | bool """ ) @@ -345,7 +345,7 @@ class TestRecursiveParentWalk(unittest.TestCase): """ - name: Compose-only task shell: compose stop x - when: DEPLOYMENT_MODE != 'swarm' + when: not IS_SWARM_MODE """ ) idx = _line_index(lines, "compose stop x") @@ -355,7 +355,7 @@ class TestRecursiveParentWalk(unittest.TestCase): lines = _lines( """ - name: Compose-only group - when: DEPLOYMENT_MODE != 'swarm' + when: not IS_SWARM_MODE block: - name: Inner shell: compose stop x @@ -368,7 +368,7 @@ class TestRecursiveParentWalk(unittest.TestCase): lines = _lines( """ - name: Outermost (compose-only) - when: DEPLOYMENT_MODE != 'swarm' + when: not IS_SWARM_MODE block: - name: Middle group block: @@ -405,7 +405,7 @@ class TestRecursiveParentWalk(unittest.TestCase): """ - name: Compose-only task shell: compose stop x - when: DEPLOYMENT_MODE == 'compose' + when: IS_COMPOSE_MODE """ ) idx = _line_index(lines, "compose stop x") @@ -422,7 +422,7 @@ class TestIsFileComposeOnlyByHeader(unittest.TestCase): lines = _lines( """ --- - # include-gated: when: DEPLOYMENT_MODE != "swarm" + # include-gated: when: not IS_SWARM_MODE - name: Task shell: compose stop x """ @@ -441,7 +441,7 @@ class TestIsFileComposeOnlyByHeader(unittest.TestCase): # line 7 # line 8 # line 9 - # include-gated: when: DEPLOYMENT_MODE != "swarm" + # include-gated: when: not IS_SWARM_MODE - name: Task shell: compose stop x """ diff --git a/utils/annotations/task_gate.py b/utils/annotations/task_gate.py index df2fc11236..9a13d39d21 100644 --- a/utils/annotations/task_gate.py +++ b/utils/annotations/task_gate.py @@ -2,7 +2,7 @@ shell calls from swarm-compat lints. A task whose `when:` evaluates compose-only at deploy time (e.g. -`when: DEPLOYMENT_MODE != 'swarm'` or `when: DEPLOYMENT_MODE == 'compose'`) +`when: not IS_SWARM_MODE` or `when: IS_COMPOSE_MODE`) never reaches a swarm host, so `compose ` / `chdir: directories.instance` inside that task body is legitimate. This module gives the lints a heuristic to recognise that gate without parsing YAML. @@ -11,7 +11,7 @@ The detection is line-based: the task block is the span between the nearest `- name:` (at indent N) above the offending line and the next top-level structural marker (`- name:` at indent <= N, or end of file). Within that span we look for any `when:` clause whose textual -value matches a compose-only DEPLOYMENT_MODE expression. +value names the compose-only boolean. """ from __future__ import annotations @@ -26,20 +26,16 @@ _TASK_NAME_RE = re.compile( r"^(?P\s*)-\s+(?:name|block|include_tasks|import_tasks|hosts)\s*:" ) _WHEN_RE = re.compile(r"^\s*when\s*:\s*(?P.+?)\s*$") -_COMPOSE_ONLY_EXPR = re.compile( - r"DEPLOYMENT_MODE\s*!=\s*['\"]swarm['\"]" - r"|DEPLOYMENT_MODE\s*==\s*['\"]compose['\"]" -) +_COMPOSE_ONLY_EXPR = re.compile(r"not\s+IS_SWARM_MODE|IS_COMPOSE_MODE") _FILE_COMPOSE_ONLY_HEADER = re.compile( - r"^\s*#\s*include-gated\s*:\s*when\s*:\s*DEPLOYMENT_MODE\s*" - r"(?:!=\s*['\"]swarm['\"]|==\s*['\"]compose['\"])" + r"^\s*#\s*include-gated\s*:\s*when\s*:\s*(?:not\s+IS_SWARM_MODE|IS_COMPOSE_MODE)" ) def is_file_compose_only_by_header(lines: Sequence[str]) -> bool: """True iff the file declares a top-of-file marker - # include-gated: when: DEPLOYMENT_MODE != "swarm" + # include-gated: when: not IS_SWARM_MODE that documents the entire file is meant to be `include_tasks:` from a parent that already carries the compose-only `when:` guard. The @@ -77,8 +73,8 @@ def is_task_compose_only_gated(lines: Sequence[str], idx: int) -> bool: """True iff the task body containing *idx* — or any enclosing parent `- block:` / `- name:` block — carries a `when:` clause whose textual expression evaluates compose-only at deploy time. Walks upwards to - recognise block-level gates: a single `when: DEPLOYMENT_MODE != - 'swarm'` on a parent `- block:` covers every child task underneath. + recognise block-level gates: a single `when: IS_COMPOSE_MODE` + on a parent `- block:` covers every child task underneath. """ cur_idx = idx while True: