mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-07 19:32:17 +00:00
`status` was too vague for what the lookup returns (apps in current
play). Rename to `deployment` and add two new fields:
* `runtime` — RUNTIME variable value
* `deployed` — runtime-aware authoritative set: equals `running`
(whitelist or groups) for ephemeral CI runtimes (act, github),
falls back to `groups` for persistent runtimes (host, dev). This
matches reality: in CI the container is fresh so only whitelisted
apps exist; in production a partial deploy still leaves prior
apps live, so groups is the right set.
Switch the two webserver/csp healthchecks to `lookup('deployment').deployed`
so they only probe domains for apps that actually exist in the current
deploy. In production behaviour is unchanged.
Update remaining consumers (cli/build/include, web-app-keycloak,
test-e2e-playwright) for the rename. Existing `status` semantics
(`whitelist`, `running`, `groups`, `all`) preserved under the new
name.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
57 lines
1.7 KiB
Python
57 lines
1.7 KiB
Python
from __future__ import annotations
|
|
|
|
from typing import Any
|
|
|
|
from ansible.plugins.lookup import LookupBase
|
|
|
|
from utils.roles.validation.invokable import list_invokable_app_ids
|
|
|
|
_STATUS_CACHE: dict[tuple, dict[str, list[str]]] = {}
|
|
|
|
_EPHEMERAL_RUNTIMES = frozenset({"act", "github"})
|
|
|
|
|
|
def _reset_cache_for_tests() -> None:
|
|
_STATUS_CACHE.clear()
|
|
|
|
|
|
def _coerce_to_list(raw: Any) -> list[str]:
|
|
# CSV input (`-e APPLICATIONS_WHITELIST=a,b`) → tokenise; `list(str)` would yield chars.
|
|
if raw is None:
|
|
return []
|
|
if isinstance(raw, str):
|
|
return [item.strip() for item in raw.split(",") if item.strip()]
|
|
return [str(item) for item in raw]
|
|
|
|
|
|
class LookupModule(LookupBase):
|
|
def run(
|
|
self,
|
|
terms: list[Any],
|
|
variables: dict[str, Any] | None = None,
|
|
**kwargs: Any,
|
|
) -> list[dict[str, list[str]]]:
|
|
vars_ = variables or getattr(self._templar, "available_variables", {}) or {}
|
|
|
|
whitelist = _coerce_to_list(vars_.get("APPLICATIONS_WHITELIST"))
|
|
groups = _coerce_to_list(vars_.get("group_names"))
|
|
runtime = str(vars_.get("RUNTIME", "")).strip().lower()
|
|
key = (tuple(whitelist), tuple(groups), runtime)
|
|
|
|
cached = _STATUS_CACHE.get(key)
|
|
if cached is not None:
|
|
return [cached]
|
|
|
|
running = whitelist or groups
|
|
deployed = list(running) if runtime in _EPHEMERAL_RUNTIMES else list(groups)
|
|
result = {
|
|
"whitelist": whitelist,
|
|
"running": list(running),
|
|
"groups": groups,
|
|
"deployed": deployed,
|
|
"runtime": runtime,
|
|
"all": list(list_invokable_app_ids()),
|
|
}
|
|
_STATUS_CACHE[key] = result
|
|
return [result]
|