mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-09 04:06:42 +00:00
3529 invalid comments in 528 files, grandfathered in while the linter only saw the working-tree diff. Removal ran through the linter's own collectors, so detection and deletion cannot drift: a comment whose opener line is blank before it and whose closer line is blank after it loses all its lines, anything else loses only the comment region, and a line left holding a bare delimiter goes with it. Five files keep their comments behind a nocheck marker instead. Four are upstream configs whose inline docs are upstream's own (mautrix, systemd journald, nextcloud-oidc-login, MediaWiki). In littlejs the commented-out entries ARE the deactivation mechanism for an example tile, so deleting them would delete configuration. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
61 lines
2.1 KiB
Python
61 lines
2.1 KiB
Python
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.domains.primary_domain import get_domain
|
|
from utils.roles.entity.name import get_entity_name
|
|
|
|
_HOST_NAME_MAX = 63
|
|
|
|
|
|
class LookupModule(LookupBase):
|
|
"""
|
|
Usage:
|
|
{{ lookup('container_hostname', application_id) }}
|
|
|
|
The Docker/OCI hostname for an application's container: its canonical
|
|
primary domain when that fits the kernel's 63-byte limit, otherwise the
|
|
short entity name (e.g. ``xwiki``). Centralises the domain-or-entity
|
|
choice so onion deployments (long ``.onion`` subdomains that overflow
|
|
sethostname(2)) never break container init.
|
|
"""
|
|
|
|
def run(self, terms, variables: dict[str, Any] | None = None, **kwargs):
|
|
if not terms or len(terms) != 1:
|
|
raise AnsibleError(
|
|
"lookup('container_hostname', application_id) expects exactly 1 term"
|
|
)
|
|
|
|
application_id = terms[0]
|
|
if not isinstance(application_id, str) or not application_id.strip():
|
|
raise AnsibleError(
|
|
"lookup('container_hostname'): application_id must be a "
|
|
f"non-empty string, got {application_id!r}"
|
|
)
|
|
application_id = application_id.strip()
|
|
|
|
variables = variables or getattr(self._templar, "available_variables", {}) or {}
|
|
|
|
domains = lookup_loader.get(
|
|
"domains",
|
|
loader=getattr(self, "_loader", None),
|
|
templar=getattr(self, "_templar", None),
|
|
).run([], variables=variables, roles_dir=kwargs.get("roles_dir"))[0]
|
|
|
|
try:
|
|
domain = get_domain(domains, application_id)
|
|
except Exception as e:
|
|
raise AnsibleError(
|
|
f"lookup('container_hostname'): failed to resolve domain for "
|
|
f"'{application_id}': {e}"
|
|
) from e
|
|
|
|
name = str(domain or "")
|
|
if 0 < len(name) <= _HOST_NAME_MAX:
|
|
return [name]
|
|
return [get_entity_name(application_id)]
|