Skip to content

Commit

Permalink
add a wait for ssh to be ready
Browse files Browse the repository at this point in the history
  • Loading branch information
nour-s committed Oct 22, 2024
1 parent 2223181 commit 59de2a1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
17 changes: 16 additions & 1 deletion scripts/configure
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,21 @@ fi
echo "Waiting for the EC2 instance to spin"
aws ec2 wait instance-running --filters Name=ip-address,Values=${gateway_ip}

# Loop until SSH is ready
echo "Waiting for SSH to be ready"
attempt=0
max_attempts=50

while ! ssh -o ConnectTimeout=5 -o StrictHostKeyChecking=no -i ./keys/ssh ubuntu@${gateway_ip} 'exit' 2>/dev/null; do
attempt=$((attempt + 1))
if [ $attempt -ge $max_attempts ]; then
echo "SSH not ready after $max_attempts attempts, exiting."
exit 1
fi
echo "SSH not ready, retrying in 2 seconds... (Attempt $attempt/$max_attempts)"
sleep 2
done

pushd ansible
ansible-playbook -i hosts $tags provision.yml
popd
popd
2 changes: 1 addition & 1 deletion scripts/init
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@ if [ ! -f $ansible_vars ]; then
> $ansible_vars
else
echo "Ansible vars file already exists, skipping"
fi
fi

0 comments on commit 59de2a1

Please sign in to comment.