From c3aa8a79792736351ae11c3849d590e350ac258e Mon Sep 17 00:00:00 2001 From: Jeremie Fraeys Date: Fri, 23 Jan 2026 14:39:46 -0500 Subject: [PATCH] CI: fix hostname self-heal logic --- .forgejo/workflows/deploy.yml | 41 ++++++++++++----------------------- 1 file changed, 14 insertions(+), 27 deletions(-) diff --git a/.forgejo/workflows/deploy.yml b/.forgejo/workflows/deploy.yml index 1c88145..fa3d505 100644 --- a/.forgejo/workflows/deploy.yml +++ b/.forgejo/workflows/deploy.yml @@ -87,33 +87,20 @@ jobs: exit 1 fi - HOSTNAME_SHORT=\"$(hostname)\" - if ! getent hosts \"$HOSTNAME_SHORT\" >/dev/null 2>&1; then - sudo -n /usr/bin/python3 - <<'PY' - import os - from pathlib import Path - - hostname = os.popen("hostname").read().strip() - hosts_path = Path("/etc/hosts") - - text = hosts_path.read_text(encoding="utf-8") if hosts_path.exists() else "" - lines = text.splitlines() - - def has_hostname() -> bool: - for line in lines: - s = line.strip() - if not s or s.startswith("#"): - continue - if hostname in s.split(): - return True - return False - - if not has_hostname(): - if text and not text.endswith("\n"): - text += "\n" - text += f"127.0.1.1 {hostname}\n" - hosts_path.write_text(text, encoding="utf-8") - PY + if ! getent hosts "$(hostname)" >/dev/null 2>&1; then + sudo -n /usr/bin/python3 -c 'import os +from pathlib import Path +hn = os.popen("hostname").read().strip() +p = Path("/etc/hosts") +t = p.read_text(encoding="utf-8") if p.exists() else "" +lines = t.splitlines() +ok = any((ln.strip() and not ln.lstrip().startswith("#") and hn in ln.split()) for ln in lines) +if not ok: + if t and not t.endswith("\n"): + t += "\n" + t += f"127.0.1.1 {hn}\n" + p.write_text(t, encoding="utf-8") +' fi sudo -n mkdir -p /opt/infra-controller /etc/infra-controller /var/lib/infra-controller /var/log/infra-controller