mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-08 03:38:23 +00:00
- plugins/lookup/status.py: `list(str)` on `APPLICATIONS_WHITELIST` (CSV from `-e`) split it into chars, breaking every consumer of `.whitelist` / `.running` (web-app-roles when-clause skipped all apps, keycloak per-app LDAP mappers never created).
- test-e2e-playwright/discover_playwright_roles: tolerate Python list-repr strings from non-native-Jinja2 stringification of `"{{ lookup('status').groups }}"` — otherwise `TEST_E2E_PLAYWRIGHT_APPS` resolves to `[]` and no spec runs.
- Unit tests cover both regressions.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
51 lines
1.4 KiB
Python
51 lines
1.4 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]]] = {}
|
|
|
|
|
|
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"))
|
|
key = (tuple(whitelist), tuple(groups))
|
|
|
|
cached = _STATUS_CACHE.get(key)
|
|
if cached is not None:
|
|
return [cached]
|
|
|
|
running = whitelist or groups
|
|
result = {
|
|
"whitelist": whitelist,
|
|
"running": list(running),
|
|
"groups": groups,
|
|
"all": list(list_invokable_app_ids()),
|
|
}
|
|
_STATUS_CACHE[key] = result
|
|
return [result]
|