CI: fix hostname self-heal logic
This commit is contained in:
parent
5bd54fc595
commit
c3aa8a7979
1 changed files with 14 additions and 27 deletions
|
|
@ -87,33 +87,20 @@ jobs:
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
HOSTNAME_SHORT=\"$(hostname)\"
|
if ! getent hosts "$(hostname)" >/dev/null 2>&1; then
|
||||||
if ! getent hosts \"$HOSTNAME_SHORT\" >/dev/null 2>&1; then
|
sudo -n /usr/bin/python3 -c 'import os
|
||||||
sudo -n /usr/bin/python3 - <<'PY'
|
from pathlib import Path
|
||||||
import os
|
hn = os.popen("hostname").read().strip()
|
||||||
from pathlib import Path
|
p = Path("/etc/hosts")
|
||||||
|
t = p.read_text(encoding="utf-8") if p.exists() else ""
|
||||||
hostname = os.popen("hostname").read().strip()
|
lines = t.splitlines()
|
||||||
hosts_path = Path("/etc/hosts")
|
ok = any((ln.strip() and not ln.lstrip().startswith("#") and hn in ln.split()) for ln in lines)
|
||||||
|
if not ok:
|
||||||
text = hosts_path.read_text(encoding="utf-8") if hosts_path.exists() else ""
|
if t and not t.endswith("\n"):
|
||||||
lines = text.splitlines()
|
t += "\n"
|
||||||
|
t += f"127.0.1.1 {hn}\n"
|
||||||
def has_hostname() -> bool:
|
p.write_text(t, encoding="utf-8")
|
||||||
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
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
sudo -n mkdir -p /opt/infra-controller /etc/infra-controller /var/lib/infra-controller /var/log/infra-controller
|
sudo -n mkdir -p /opt/infra-controller /etc/infra-controller /var/lib/infra-controller /var/log/infra-controller
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue