fix(deploy-node): resolve HOST_DIR via os_hostname lookup, not bare hostname

Replaces the brittle `hosts/$(hostname|lower)` assumption with a scan
of hosts/*/host.yaml for a matching os_hostname field. This fixes VPS
where the OS hostname (ubuntu-4gb-hel1-1) never matched the repo
directory (hosts/vps/), causing a silent "No services found" false-green.

Fallback to lowercase-hostname dir preserved for nodes that haven't yet
received the os_hostname field; exits 1 with a clear message if neither
match nor fallback directory exists.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
oskar 2026-06-24 22:24:40 +02:00
parent 644f32d2f7
commit ae739b5037

View file

@ -8,7 +8,7 @@ set -e
REPO_PATH="${HOME}/homelab-codex-ws"
RUNTIME_PATH="/opt/homelab"
HOSTNAME=$(hostname | tr '[:lower:]' '[:upper:]')
HOST_DIR="${REPO_PATH}/hosts/$(hostname | tr '[:upper:]' '[:lower:]')"
CURRENT_OS_HOST=$(hostname)
echo "--- Starting Deployment on ${HOSTNAME} ---"
@ -22,6 +22,38 @@ cd "$REPO_PATH"
echo "Pulling latest changes..."
git pull
# Resolve host directory: search hosts/*/host.yaml for os_hostname == $(hostname)
HOST_LOGICAL=$(python3 -c "
import yaml, os, sys
current = '${CURRENT_OS_HOST}'
hosts_dir = os.path.join('${REPO_PATH}', 'hosts')
for entry in sorted(os.listdir(hosts_dir)):
host_yaml = os.path.join(hosts_dir, entry, 'host.yaml')
if not os.path.isfile(host_yaml):
continue
try:
with open(host_yaml) as f:
data = yaml.safe_load(f)
if data and data.get('os_hostname') == current:
print(entry)
sys.exit(0)
except Exception:
pass
")
if [ -n "$HOST_LOGICAL" ]; then
HOST_DIR="${REPO_PATH}/hosts/${HOST_LOGICAL}"
else
HOST_LOGICAL_FB="$(echo "$CURRENT_OS_HOST" | tr '[:upper:]' '[:lower:]')"
echo "WARN: no os_hostname match for ${CURRENT_OS_HOST}, falling back to lowercase hostname dir" >&2
HOST_DIR="${REPO_PATH}/hosts/${HOST_LOGICAL_FB}"
fi
if [ ! -d "$HOST_DIR" ]; then
echo "Error: No host directory found for ${CURRENT_OS_HOST} (tried ${HOST_DIR})" >&2
exit 1
fi
# 2. Identify Services
SERVICES=()
if [ -f "${HOST_DIR}/services.txt" ]; then