mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-06 19:01:54 +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
28 lines
795 B
Python
28 lines
795 B
Python
from __future__ import annotations
|
|
|
|
import subprocess
|
|
from typing import Dict, List, Optional
|
|
|
|
|
|
def run_subprocess(
|
|
cmd: List[str],
|
|
capture_output: bool = False,
|
|
env: Optional[Dict[str, str]] = None,
|
|
) -> subprocess.CompletedProcess:
|
|
"""
|
|
Run a subprocess command and either stream output or capture it.
|
|
Raise SystemExit on non-zero return code.
|
|
"""
|
|
if capture_output:
|
|
result = subprocess.run(cmd, text=True, capture_output=True, env=env)
|
|
else:
|
|
result = subprocess.run(cmd, text=True, env=env)
|
|
|
|
if result.returncode != 0:
|
|
msg = f"Command failed: {' '.join(str(c) for c in cmd)}\n"
|
|
if capture_output:
|
|
msg += f"STDOUT:\n{result.stdout}\nSTDERR:\n{result.stderr}\n"
|
|
raise SystemExit(msg)
|
|
|
|
return result
|