ci: unify into matrix ansible-deploy.yml, add ansible-lint.yml and exit_nodes group
ansible-deploy / plan (push) Successful in 1s
ansible-deploy / deploy (core-secrets, ) (push) Successful in 17s
ansible-lint / lint (push) Failing after 3s
ansible-deploy / deploy (core-mon, ) (push) Successful in 26s
ansible-deploy / deploy (core-net, ) (push) Successful in 52s
ansible-deploy / deploy (ger-nod-02, ) (push) Successful in 1m18s
ansible-deploy / deploy (opnsense, ) (push) Successful in 9s
ansible-deploy / deploy (rus-central, ) (push) Successful in 52s

This commit is contained in:
karpenok committed 2026-11-15 22:44:34 +07:00
1 parent 189e31e266
commit fd0dcab300
18 files changed
+243 -278

No files matched your search

+70
View File
@@ -0,0 +1,70 @@
#!/usr/bin/env python3
"""Вычисляет матрицу затронутых машин для Gitea Actions (ansible-deploy.yml)."""
from __future__ import annotations
import json
import os
import subprocess
import sys
from pathlib import Path
SKIP_PLAYBOOKS = {"site", "host", "core-git"}
def list_machines(playbooks_dir: Path) -> list[str]:
machines = []
for p in sorted(playbooks_dir.glob("*.yml")):
name = p.stem
if name not in SKIP_PLAYBOOKS:
machines.append(name)
return machines
def main() -> int:
event = os.environ.get("EVENT_NAME", "push").strip()
before = os.environ.get("EVENT_BEFORE", "").strip()
after = os.environ.get("EVENT_SHA", "").strip()
input_machine = os.environ.get("INPUT_MACHINE", "all").strip()
input_tags = os.environ.get("INPUT_TAGS", "").strip()
root = Path(__file__).resolve().parents[2]
machines = list_machines(root / "ansible" / "playbooks")
include: list[dict[str, str]] = []
if event == "workflow_dispatch":
selected = machines if input_machine in ("", "all") else [input_machine]
for m in selected:
if m not in machines:
print(f"Неизвестная или запрещённая для CI машина: {m}", file=sys.stderr)
return 2
include.append({"machine": m, "tags": input_tags})
else:
for m in machines:
proc = subprocess.run(
["sh", str(root / "ansible" / "ci" / "ansible-target.sh"), m, event, before, after],
cwd=root,
capture_output=True,
text=True,
check=False,
)
if proc.returncode != 0:
print(proc.stderr, file=sys.stderr, end="")
return proc.returncode
if proc.stdout.strip():
include.append({"machine": m, "tags": ""})
matrix_json = json.dumps({"include": include}, separators=(",", ":"))
has_targets = "true" if include else "false"
print(f"Planned targets: {matrix_json}")
gh_out = os.environ.get("GITHUB_OUTPUT")
if gh_out:
with open(gh_out, "a", encoding="utf-8") as fh:
fh.write(f"matrix={matrix_json}\n")
fh.write(f"has_targets={has_targets}\n")
return 0
if __name__ == "__main__":
raise SystemExit(main())