mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-13 06:06:38 +00:00
The frontend and its sso, logout, dashboard and prometheus consumers were
gated on 'svc-net-tor' not in group_names, written when a Tor node served
onion only. On a multi node that removed the clearnet filer vhost, so the
storage specs of every SeaweedFS consumer failed on a clearnet pick with
ERR_SSL_UNRECOGNIZED_NAME_ALERT on filer.<domain>.
lookup('network_served', <network>, *role_ids) answers whether the node's
resolved NETWORK_MODE serves a network and every named role is deployed.
The gates use it instead of restating the mode resolution and the provider
check, so the frontend now drops only on a tor-only node. is_explicit_truth
registers the lookup in GATED_LOOKUPS so the static closure still reads
those flags as dynamic, and the dynamic-flag and universal-logout checks ask
is_explicit_truth instead of matching "in group_names" themselves.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
46 lines
1.7 KiB
Python
46 lines
1.7 KiB
Python
"""Whether this host serves one registry network, optionally with given roles deployed."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import Any
|
|
|
|
from ansible.errors import AnsibleError
|
|
from ansible.plugins.lookup import LookupBase
|
|
|
|
from utils.networks.reachability import (
|
|
NODE_MODES,
|
|
network,
|
|
resolve_node_mode,
|
|
tor_serves_host,
|
|
)
|
|
|
|
|
|
class LookupModule(LookupBase):
|
|
"""
|
|
Usage:
|
|
{{ lookup('network_served', network_name) }}
|
|
{{ lookup('network_served', network_name, role_id, ...) }}
|
|
|
|
Returns True when the node's resolved ``NETWORK_MODE`` serves
|
|
``network_name`` and every given ``role_id`` is in ``group_names``.
|
|
"""
|
|
|
|
def run(self, terms, variables: dict[str, Any] | None = None, **kwargs):
|
|
if not terms or not str(terms[0] or "").strip():
|
|
raise AnsibleError(
|
|
"lookup('network_served', network, *role_ids) expects a network"
|
|
)
|
|
variables = variables or getattr(self._templar, "available_variables", {}) or {}
|
|
templar = getattr(self, "_templar", None)
|
|
raw_mode = variables.get("NETWORK_MODE") or ""
|
|
if templar is not None and isinstance(raw_mode, str):
|
|
raw_mode = templar.template(raw_mode)
|
|
try:
|
|
name = network(str(terms[0]).strip()).name
|
|
mode = resolve_node_mode(raw_mode, tor_provided=tor_serves_host(variables))
|
|
except ValueError as exc:
|
|
raise AnsibleError(f"network_served: {exc}") from exc
|
|
deployed = set(variables.get("group_names") or [])
|
|
roles = [str(role).strip() for role in terms[1:]]
|
|
return [name in NODE_MODES[mode] and all(role in deployed for role in roles)]
|