forked from fediversity/fediversity
factor out await.ssh
Signed-off-by: Kiara Grouwstra <kiara@procolix.eu>
This commit is contained in:
parent
ca304932b6
commit
98bc0754cc
2 changed files with 32 additions and 17 deletions
31
deployment/run/tf-proxmox/await-ssh.sh
Normal file
31
deployment/run/tf-proxmox/await-ssh.sh
Normal 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
|
||||
|
|
@ -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"
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue