mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-08 19:56:53 +00:00
The entity name keys a role's instance directory, its compose project and its container name, and was derived only by stripping the longest matching category prefix. Two roles under different categories whose names share a suffix therefore collapse onto one entity and overwrite each other's rendered stack, which no provides: can repair. A literal entity_name in vars/main.yml now wins over the derivation. web-app-seaweedfs-console takes its shorter name back and declares the entity seaweedfs-console, which frees the seaweedfs key in its own services map for the engine consumer and removes the provides:, covers: and alias entries that stood in for it. A new lint pairs the declaration with the primary key it has to match, because a drift between them would drop the role from the provider set in silence. Compared across all 288 roles, exactly one entity changes, and it restores what main already keeps on disk, so no instance directory moves. The function and the filter lose their get_ prefix. Two lints read that prefix as the discriminator between the variable and the filter that fills it; both discriminate on the pipe now. Ansible's templar resolves a filter and a same-named variable independently, verified against ansible-core 2.20.2. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
60 lines
2.0 KiB
Python
60 lines
2.0 KiB
Python
"""Lookup ``compose_networks``: emit the top-level ``networks:`` block for
|
|
a compose file. Reads the service_registry, the rendering role's
|
|
``application_id`` and ``DEPLOYMENT_MODE`` from variables.
|
|
|
|
Usage in any ``compose.yml.j2``:
|
|
|
|
{{ lookup('compose_networks') }}
|
|
|
|
The output starts at column 0 (no caller-side indent).
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import Any
|
|
|
|
from ansible.errors import AnsibleError
|
|
from ansible.plugins.lookup import LookupBase
|
|
|
|
from utils.networks.lookup_context import build_context, resolve_var
|
|
from utils.networks.render import render_compose_networks
|
|
from utils.roles.entity.name import entity_name
|
|
|
|
|
|
class LookupModule(LookupBase):
|
|
def run(
|
|
self,
|
|
terms: list[Any] | None,
|
|
variables: dict[str, Any] | None = None,
|
|
**kwargs: Any,
|
|
) -> list[str]:
|
|
if terms:
|
|
raise AnsibleError("compose_networks lookup takes no positional terms")
|
|
|
|
ctx = build_context(self, variables)
|
|
|
|
application_id = resolve_var(ctx.templar, ctx.vars.get("application_id"))
|
|
if not application_id:
|
|
raise AnsibleError(
|
|
"compose_networks lookup: application_id is required in variables"
|
|
)
|
|
|
|
swarm_cfg = resolve_var(ctx.templar, ctx.vars.get("swarm", {})) or {}
|
|
net_cfg = swarm_cfg.get("network", {}) if isinstance(swarm_cfg, dict) else {}
|
|
swarm_encrypted = True
|
|
if isinstance(net_cfg, dict) and "encryption" in net_cfg:
|
|
swarm_encrypted = bool(net_cfg.get("encryption"))
|
|
|
|
return [
|
|
render_compose_networks(
|
|
application_id=str(application_id),
|
|
deployment_mode=ctx.deployment_mode,
|
|
registry=ctx.registry,
|
|
entity_name=entity_name,
|
|
lookup_config=ctx.lookup_config,
|
|
lookup_database=ctx.lookup_database,
|
|
swarm_encrypted=swarm_encrypted,
|
|
node_local=bool(kwargs.get("node_local", False)),
|
|
)
|
|
]
|