mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-13 06:06:38 +00:00
Tighten the utils namespace so each subpackage owns one concern:
- utils/applications/* moves under utils/roles/applications/* (helpers
that operate on the runtime applications dict and meta/services.yml).
- utils/service_registry.py and utils/database_service.py move under
utils/roles/applications/services/ as registry.py and database.py.
- utils/entity_name_utils.py becomes utils/roles/entity_name.py.
- utils/invokable.py, utils/valid_deploy_id.py, and the existing
utils/roles/resource_validation.py group under utils/roles/validation/
as invokable.py, deploy_id.py, and resources.py.
- utils/templating.py and utils/jinja_strict.py split into
utils/templating/ansible.py (Templar + TrustedAsTemplate, lookup-env
shortcut) and utils/templating/jinja.py (vanilla Jinja2 Environment,
multi-pass strict render).
Every caller in utils, cli, plugins, roles/<role>/{filter,lookup}_plugins,
tests, and the docs that link to the moved files is updated to the new
import paths. Test files mirror the new source layout
(tests/unit/utils/{roles,templating}/...).
New READMEs at utils/cleanup/, utils/roles/, utils/roles/applications/services/,
utils/roles/validation/, and utils/templating/ follow the
documentation.md and readme_md.md guidelines.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
54 lines
1.5 KiB
Python
54 lines
1.5 KiB
Python
from __future__ import annotations
|
|
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
|
|
def _dump_inventory_full(inventory: str) -> None:
|
|
"""
|
|
Print the full inventory file content (raw) to simplify CI debugging.
|
|
"""
|
|
|
|
print("\n[DEBUG] Full inventory dump:")
|
|
print(f"[DEBUG] inventory path: {inventory}")
|
|
|
|
if not Path(inventory).exists():
|
|
print("[DEBUG] inventory file does not exist")
|
|
return
|
|
|
|
try:
|
|
with Path(inventory).open(encoding="utf-8", errors="replace") as f:
|
|
content = f.read()
|
|
|
|
print("\n===== BEGIN INVENTORY FILE =====")
|
|
print(content.rstrip("\n"))
|
|
print("===== END INVENTORY FILE =====\n")
|
|
except Exception as exc:
|
|
print(f"[DEBUG] failed to read inventory: {exc}")
|
|
|
|
|
|
def validate_application_ids(inventory: str, app_ids: list[str]) -> None:
|
|
"""Validate requested application IDs using ValidDeployId."""
|
|
if not app_ids:
|
|
return
|
|
|
|
from utils.roles.validation.deploy_id import ValidDeployId
|
|
|
|
validator = ValidDeployId()
|
|
invalid = validator.validate(inventory, app_ids)
|
|
|
|
if not invalid:
|
|
return
|
|
|
|
print("\n[ERROR] Some application_ids are invalid for this inventory:\n")
|
|
for app_id, status in invalid.items():
|
|
reasons = []
|
|
if not status.get("in_roles", True):
|
|
reasons.append("not defined as a role")
|
|
if not status.get("in_inventory", True):
|
|
reasons.append("not present in inventory")
|
|
print(f" - {app_id}: {', '.join(reasons)}")
|
|
|
|
_dump_inventory_full(inventory)
|
|
sys.exit(1)
|