mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-10 04:36:40 +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>
61 lines
1.8 KiB
Python
61 lines
1.8 KiB
Python
from __future__ import annotations
|
|
|
|
import argparse
|
|
import re
|
|
import sys
|
|
import tarfile
|
|
from pathlib import Path
|
|
|
|
from yaml import YAMLError
|
|
|
|
from cli.administration.roles.paths import WORK_DIR
|
|
from cli.administration.roles.placement import pull
|
|
from utils.cache import ROLES_DIR
|
|
from utils.roles.custom import CustomRoleError
|
|
|
|
_URL_USERINFO = re.compile(r"(?<=://)[^/\s@'\"]+@")
|
|
|
|
|
|
def build_parser() -> argparse.ArgumentParser:
|
|
parser = argparse.ArgumentParser(
|
|
description=(
|
|
"Pull the custom roles (web-app-cst-*) an inventory declares into "
|
|
"roles/, replace the ones an earlier pull placed and remove the ones "
|
|
"it no longer declares, without deploying."
|
|
),
|
|
)
|
|
parser.add_argument(
|
|
"inventory",
|
|
help="Inventory file or directory, or an inline host list such as 'localhost,'.",
|
|
)
|
|
return parser
|
|
|
|
|
|
def pull_or_exit(inventory: str) -> list[str]:
|
|
"""Pull the custom roles of *inventory*; exit 1 when the pull is refused.
|
|
|
|
The reason never carries the credentials of a URL.
|
|
|
|
Args:
|
|
inventory: the inventory file or directory, or an inline host list.
|
|
|
|
Returns:
|
|
One line per placed, removed or untouched custom role; none and
|
|
no output when nothing is declared or placed.
|
|
"""
|
|
try:
|
|
lines = pull(Path(inventory), ROLES_DIR, WORK_DIR)
|
|
except (CustomRoleError, OSError, tarfile.TarError, YAMLError) as exc:
|
|
reason = _URL_USERINFO.sub("***@", str(exc))
|
|
print(f"\n[ERROR] Custom roles refused:\n{reason}\n", file=sys.stderr)
|
|
sys.exit(1)
|
|
for line in lines:
|
|
print(f"custom role {line}", flush=True)
|
|
return lines
|
|
|
|
|
|
def main(argv: list[str] | None = None) -> int:
|
|
args = build_parser().parse_args(argv)
|
|
pull_or_exit(args.inventory)
|
|
return 0
|