fix(api): install ansible runtime for truth chain
This commit is contained in:
@@ -9,6 +9,7 @@ from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import json
|
||||
import os
|
||||
import shutil
|
||||
from datetime import UTC, date, datetime, timedelta
|
||||
from decimal import Decimal
|
||||
@@ -716,7 +717,15 @@ def _ansible_playbook_roots(module_path: Path | None = None) -> list[Path]:
|
||||
]
|
||||
|
||||
|
||||
def _ansible_runtime_readiness() -> dict[str, Any]:
|
||||
def _path_readable(path: Path) -> bool:
|
||||
return path.exists() and path.is_file() and os.access(path, os.R_OK)
|
||||
|
||||
|
||||
def _ansible_runtime_readiness(
|
||||
*,
|
||||
repair_ssh_key_path: Path = Path("/etc/repair-ssh/id_ed25519"),
|
||||
repair_known_hosts_path: Path = Path("/etc/repair-known-hosts/known_hosts"),
|
||||
) -> dict[str, Any]:
|
||||
playbook_roots = _ansible_playbook_roots()
|
||||
playbook_root = next((path for path in playbook_roots if path.exists()), None)
|
||||
playbook_paths = (
|
||||
@@ -726,6 +735,8 @@ def _ansible_runtime_readiness() -> dict[str, Any]:
|
||||
)
|
||||
inventory_path = playbook_root / "inventory" / "hosts.yml" if playbook_root is not None else None
|
||||
binary_path = shutil.which("ansible-playbook")
|
||||
repair_ssh_key_readable = _path_readable(repair_ssh_key_path)
|
||||
repair_known_hosts_readable = _path_readable(repair_known_hosts_path)
|
||||
blockers: list[str] = []
|
||||
if not binary_path:
|
||||
blockers.append("ansible_playbook_binary_missing")
|
||||
@@ -735,6 +746,10 @@ def _ansible_runtime_readiness() -> dict[str, Any]:
|
||||
blockers.append("ansible_inventory_missing")
|
||||
if not playbook_paths:
|
||||
blockers.append("ansible_playbooks_missing")
|
||||
if not repair_ssh_key_readable:
|
||||
blockers.append("ansible_repair_ssh_key_missing")
|
||||
if not repair_known_hosts_readable:
|
||||
blockers.append("ansible_repair_known_hosts_missing")
|
||||
|
||||
return {
|
||||
"ansible_playbook_binary_present": bool(binary_path),
|
||||
@@ -743,6 +758,12 @@ def _ansible_runtime_readiness() -> dict[str, Any]:
|
||||
"playbook_root": str(playbook_root) if playbook_root is not None else None,
|
||||
"inventory_present": bool(inventory_path and inventory_path.exists()),
|
||||
"playbook_count": len(playbook_paths),
|
||||
"repair_ssh_key_present": repair_ssh_key_path.exists(),
|
||||
"repair_ssh_key_readable": repair_ssh_key_readable,
|
||||
"repair_ssh_key_path": str(repair_ssh_key_path),
|
||||
"repair_known_hosts_present": repair_known_hosts_path.exists(),
|
||||
"repair_known_hosts_readable": repair_known_hosts_readable,
|
||||
"repair_known_hosts_path": str(repair_known_hosts_path),
|
||||
"can_run_check_mode": not blockers,
|
||||
"blockers": blockers,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user