factor out await.ssh

Signed-off-by: Kiara Grouwstra <kiara@procolix.eu>
This commit is contained in:
Kiara Grouwstra 2025-10-19 19:22:21 +02:00
parent ca304932b6
commit 98bc0754cc
Signed by: kiara
SSH key fingerprint: SHA256:COspvLoLJ5WC5rFb9ZDe5urVCkK4LJZOsjfF4duRJFU
2 changed files with 32 additions and 17 deletions

View file

@ -0,0 +1,31 @@
#! /usr/bin/env bash
set -xeuo pipefail
declare username host key_file ssh_opts
readarray -t ssh_opts < <(echo "$ssh_opts" | jq -r '.[]')
sshOpts=(
-o BatchMode=yes \
-o StrictHostKeyChecking=no \
-o ConnectTimeout=5 \
-o ServerAliveInterval=5 \
)
if [[ -n "${key_file}" ]]; then
sshOpts+=(
-i "${key_file}"
)
fi
for ssh_opt in "${ssh_opts[@]}"; do
sshOpts+=(
-o "${ssh_opt}"
)
done
for i in $(seq 1 30); do
if ssh "${sshOpts[@]}" "${username}@${host}" "true"; then
exit 0
fi
echo "Waiting for SSH (attempt #$i)..."
sleep 5
done
echo "SSH never came up!" >&2
exit 1

View file

@ -182,23 +182,7 @@ resource "null_resource" "wait_for_ssh" {
proxmox_virtual_environment_vm.nix_vm
]
provisioner "local-exec" {
command = <<-EOT
for i in $(seq 1 30); do
if ssh -vvv \
-i "${var.key_file}" \
-o BatchMode=yes \
-o StrictHostKeyChecking=no \
-o ConnectTimeout=1 \
-o ServerAliveInterval=1 \
root@${proxmox_virtual_environment_vm.nix_vm.ipv4_addresses[1][0]} "true"; then
exit 0
fi
echo "Waiting for SSH (attempt #$i)..."
sleep 5
done
echo "SSH never came up!" >&2
exit 1
EOT
command = "username=root host=${proxmox_virtual_environment_vm.nix_vm.ipv4_addresses[1][0]} key_file=${var.key_file} ssh_opts='${var.ssh_opts}' ./await-ssh.sh"
}
}