2021-06-25 01:45:51 +02:00
|
|
|
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" > /dev/null 2>&1 && pwd)"
|
2021-05-03 15:03:26 +02:00
|
|
|
. "$DIR/prelude.sh"
|
|
|
|
|
|
|
|
if [ "Windows_NT" = "$OS" ]; then
|
|
|
|
user=Administrator
|
|
|
|
else
|
|
|
|
user=$USER
|
|
|
|
fi
|
2021-06-25 01:45:51 +02:00
|
|
|
hostname=$(tr -d '"[]{}' < src/hosts.yml | cut -d , -f 1 | awk -F : '{print $2}')
|
2021-05-03 15:03:26 +02:00
|
|
|
|
|
|
|
# To add the hostname to expansions.
|
2021-06-25 01:45:51 +02:00
|
|
|
echo "private_ip_address: $hostname" >> src/powercycle_ip_address.yml
|
2021-05-03 15:03:26 +02:00
|
|
|
|
|
|
|
echo $hostname
|
|
|
|
echo $user
|
|
|
|
|
|
|
|
attempts=0
|
2021-05-19 10:21:43 +02:00
|
|
|
connection_attempts=60
|
2021-05-03 15:03:26 +02:00
|
|
|
|
|
|
|
# Check for remote connectivity
|
|
|
|
while ! ssh \
|
|
|
|
-i ${private_key_file} \
|
|
|
|
-o ConnectTimeout=10 \
|
|
|
|
-o ForwardAgent=yes \
|
|
|
|
-o IdentitiesOnly=yes \
|
|
|
|
-o StrictHostKeyChecking=no \
|
|
|
|
"$(printf "%s@%s" "$user" "$hostname")" \
|
2021-06-25 01:45:51 +02:00
|
|
|
exit 2> /dev/null; do
|
2021-05-03 15:03:26 +02:00
|
|
|
[ "$attempts" -ge "$connection_attempts" ] && exit 1
|
|
|
|
((attempts++))
|
|
|
|
printf "SSH connection attempt %d/%d failed. Retrying...\n" "$attempts" "$connection_attempts"
|
|
|
|
# sleep for Permission denied (publickey) errors
|
|
|
|
sleep 10
|
|
|
|
done
|