mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-28 13:57:43 +00:00
The handover condition lived as the same inline Jinja in basic.conf.j2,
ws_generic.conf.j2 and Baserow's proxy.conf.j2. Move it into
lookup('network_handover', application_id, domain), which also refuses a
non-boolean flag, and use it at all three places.
A handover sibling still proxies its health, MCP and SSO endpoints to the
backend, and those requests carried the onion Host, which single-URL apps
reject: pretix answered /healthz/ready on the onion with 400 Unknown host
and failed the Prometheus blackbox probe. forwarded.conf.j2 now sends the
canonical domain as Host and X-Forwarded-Host on a handover sibling, so the
onion probe keeps measuring the backend through the onion vhost.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
48 lines
1.8 KiB
Python
48 lines
1.8 KiB
Python
"""Whether a vhost is a network sibling its application hands over to clearnet."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import Any
|
|
|
|
from ansible.errors import AnsibleError
|
|
from ansible.plugins.loader import lookup_loader
|
|
from ansible.plugins.lookup import LookupBase
|
|
|
|
from utils.networks.reachability import network_of
|
|
|
|
|
|
class LookupModule(LookupBase):
|
|
"""
|
|
Usage:
|
|
{{ lookup('network_handover', application_id, domain) }}
|
|
|
|
Returns True when ``application_id`` opts into
|
|
``networks.reachability.handover`` and ``domain`` lies in another network
|
|
than the application's canonical domain, so its vhost only redirects there.
|
|
"""
|
|
|
|
def run(self, terms, variables: dict[str, Any] | None = None, **kwargs):
|
|
if not terms or len(terms) != 2 or not all(str(t or "").strip() for t in terms):
|
|
raise AnsibleError(
|
|
"lookup('network_handover', application_id, domain) expects two terms"
|
|
)
|
|
variables = variables or getattr(self._templar, "available_variables", {}) or {}
|
|
templar = getattr(self, "_templar", None)
|
|
application_id, domain = (str(term).strip() for term in terms)
|
|
|
|
def _run(name: str, *args: Any) -> Any:
|
|
return lookup_loader.get(name, loader=self._loader, templar=templar).run(
|
|
list(args), variables=variables
|
|
)[0]
|
|
|
|
handover = _run(
|
|
"config", application_id, "networks.reachability.handover", False
|
|
)
|
|
if not isinstance(handover, bool):
|
|
raise AnsibleError(
|
|
f"network_handover: {application_id}: networks.reachability.handover must be a boolean"
|
|
)
|
|
if not handover:
|
|
return [False]
|
|
return [network_of(domain) != network_of(str(_run("domain", application_id)))]
|