GRM-17: fix grm list still showing unknown status for active runners
- run_ad_hoc() now accepts ask_become_pass and check parameters - list_runners() passes ask_become_pass=True so --ask-become-pass is added when running in a TTY, matching playbook behavior - list_runners() passes check=False so systemctl is-active non-zero exit codes (inactive=3, unknown=4) don't raise exceptions; the actual status string is parsed from stdout instead - TTY guard prevents --ask-become-pass from hanging in non-interactive environments (CI, scripts) - 123 tests, 100% coverage, pyright clean, ruff clean
This commit is contained in:
@@ -6,6 +6,7 @@ import logging
|
||||
import os
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
|
||||
@@ -85,6 +86,8 @@ class AnsibleExecutor:
|
||||
module: str,
|
||||
args: str,
|
||||
become: bool = False,
|
||||
ask_become_pass: bool = False,
|
||||
check: bool = True,
|
||||
) -> str:
|
||||
"""Run an Ansible ad-hoc command and return stdout."""
|
||||
cmd = [
|
||||
@@ -101,6 +104,8 @@ class AnsibleExecutor:
|
||||
cmd.extend(["--private-key", key])
|
||||
if become:
|
||||
cmd.append("--become")
|
||||
if become and ask_become_pass and sys.stdin.isatty():
|
||||
cmd.append("--ask-become-pass")
|
||||
|
||||
env = os.environ.copy()
|
||||
proc = subprocess.run(
|
||||
@@ -109,7 +114,7 @@ class AnsibleExecutor:
|
||||
capture_output=True,
|
||||
text=True,
|
||||
)
|
||||
if proc.returncode != 0:
|
||||
if check and proc.returncode != 0:
|
||||
stderr = proc.stderr.strip() if proc.stderr else ""
|
||||
raise AnsibleError(
|
||||
_(
|
||||
|
||||
@@ -282,7 +282,14 @@ class RunnerManager:
|
||||
mode = info.get("mode", "docker")
|
||||
try:
|
||||
stdout = self._executor.run_ad_hoc(
|
||||
host, user, key, "shell", f"systemctl is-active gitea-runner@{name}", become=True
|
||||
host,
|
||||
user,
|
||||
key,
|
||||
"shell",
|
||||
f"systemctl is-active gitea-runner@{name}",
|
||||
become=True,
|
||||
ask_become_pass=True,
|
||||
check=False,
|
||||
)
|
||||
# Filter out ansible noise (SSH warnings etc)
|
||||
lines = [ln for ln in stdout.splitlines() if ln.strip() and not ln.startswith(("[WARNING]", "ssh:"))]
|
||||
|
||||
Reference in New Issue
Block a user