mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-29 22:37:29 +00:00
An inventory group web-app-cst-<name> with applications.<id>.custom: true and
a pinned source {url, version, path} is pulled into roles/ before the play,
read raw (Jinja, Ansible tags and credential URLs refused), placed through a
staging directory under an exclusive lock, and owned by a marker that names
its own directory, so a pull or roles-clean never replaces or removes a
directory it did not place and a failed pull leaves roles/ as it was.
Directory inventories, host lists and non-UTF-8 files behave as Ansible
reads them; generated test deploys pass --skip-pull. make roles-pull,
roles-clean and roles list, INFINITO_EXTRA_MOUNTS for local sources, the
web-app-cst category, the reserved prefix lint and a central
repository_files() that also yields the gitignored custom roles let every
lint scan them like in-tree roles. Supersedes the uncommitted 045 External
Roles draft and reuses its fetch, sync and mount design.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
43 lines
1.8 KiB
Python
43 lines
1.8 KiB
Python
"""Application-block validation: host_vars keys vs role contract."""
|
||
|
||
from __future__ import annotations
|
||
|
||
from utils.manager.credential_key import OVERRIDE_SECTION, SECRETS_KEY
|
||
from utils.roles.custom import CUSTOM_KEY, SOURCE_KEY, is_custom
|
||
|
||
from .keys import recursive_keys
|
||
|
||
|
||
def _declares_custom_role(app_id: str, key: str) -> bool:
|
||
return is_custom(app_id) and key.split(".", 1)[0] in (CUSTOM_KEY, SOURCE_KEY)
|
||
|
||
|
||
def compare_application_keys(applications, application_defaults, source, variants=None):
|
||
"""Variants.yml is part of the role contract: a variant overlay may
|
||
legitimately introduce service-keys absent from meta/services.yml
|
||
(e.g. roles/web-opt-rdr-www declares services.dashboard only in
|
||
meta/variants.yml). Widen the allow-set to defaults ∪ union(variant
|
||
overlays) so host_vars baked by matrix-deploy from variants.yml
|
||
aren't flagged as "Missing default".
|
||
|
||
``custom`` and ``source`` of a custom role are the inventory's
|
||
declaration of where the role comes from, not role settings, so no
|
||
role default carries them."""
|
||
variants = variants or {}
|
||
errs: list[str] = []
|
||
for app_id, conf in applications.items():
|
||
if app_id not in application_defaults:
|
||
errs.append(f"{source}: Unknown application '{app_id}'")
|
||
continue
|
||
legal_keys = recursive_keys(application_defaults[app_id])
|
||
for variant in variants.get(app_id, []):
|
||
legal_keys |= recursive_keys(variant)
|
||
for key in recursive_keys(conf):
|
||
if key == SECRETS_KEY or key.startswith(OVERRIDE_SECTION):
|
||
continue
|
||
if _declares_custom_role(app_id, key):
|
||
continue
|
||
if key not in legal_keys:
|
||
errs.append(f"{source}: Missing default for {app_id}: {key}")
|
||
return errs
|