Files
computer-playbook/plugins/lookup/deployment.py
T
kevinveenbirkenbachandClaude Opus 5.5 ca4f53d0e4 fix(mcp): keep a persistent host's providers through a partial deploy
mcp_servers narrowed the MCP providers to application_closure(deployment.whitelist), which on a persistent host drops every provider an earlier run deployed and a partial run does not touch. sys-svc-mcp-reconcile then converges each client present on the host against that narrowed set: on echoserver the --id web-opt-rdr-domains run rdr-3 removed the Prometheus registration from Flowise.

deployment now reports ephemeral (runtime act or github), and the closure narrows only there, where a whitelist is all a run deploys; a persistent host narrows nothing, as a full deploy already did with its empty whitelist, so its clients keep every provider it serves. CI keeps its narrowing unchanged.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-25 09:24:28 +01:00

66 lines
1.9 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"})
_IMPLICIT_GROUPS = frozenset({"all", "ungrouped"})
def _reset_cache_for_tests() -> None:
_STATUS_CACHE.clear()
def _coerce_to_list(raw: Any) -> list[str]:
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"))
inventory = sorted(
name
for name, hosts in (vars_.get("groups") or {}).items()
if hosts and name not in _IMPLICIT_GROUPS
)
runtime = str(vars_.get("RUNTIME", "")).strip().lower()
key = (tuple(whitelist), tuple(groups), tuple(inventory), runtime)
cached = _STATUS_CACHE.get(key)
if cached is not None:
return [cached]
running = whitelist or groups
ephemeral = runtime in _EPHEMERAL_RUNTIMES
deployed = list(running) if ephemeral else list(groups)
result = {
"whitelist": whitelist,
"running": list(running),
"groups": groups,
"inventory": inventory,
"deployed": deployed,
"runtime": runtime,
"ephemeral": ephemeral,
"all": list(list_invokable_app_ids()),
}
_STATUS_CACHE[key] = result
return [result]