mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-09 12:17:13 +00:00
- Split create-inventory logic into focused modules (cli, project, filters, host_vars, credentials, etc.) - Replace fragile path construction with python -m module execution - Add robust project root detection - Centralize password generation - Improve test coverage with per-module unit tests - Preserve existing inventory and host_vars behavior https://chatgpt.com/share/69471157-79c0-800f-8dec-25c0f8e38f03
23 lines
654 B
Python
23 lines
654 B
Python
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
from typing import Any, Dict
|
|
|
|
import yaml
|
|
|
|
|
|
def load_yaml(path: Path) -> Dict[str, Any]:
|
|
if not path.exists():
|
|
return {}
|
|
with path.open("r", encoding="utf-8") as f:
|
|
data = yaml.safe_load(f) or {}
|
|
if not isinstance(data, dict):
|
|
raise SystemExit(f"Expected a mapping at top-level in {path}, got {type(data)}")
|
|
return data
|
|
|
|
|
|
def dump_yaml(path: Path, data: Dict[str, Any]) -> None:
|
|
path.parent.mkdir(parents=True, exist_ok=True)
|
|
with path.open("w", encoding="utf-8") as f:
|
|
yaml.safe_dump(data, f, sort_keys=False, default_flow_style=False)
|