-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.sh
More file actions
executable file
·40 lines (31 loc) · 976 Bytes
/
deploy.sh
File metadata and controls
executable file
·40 lines (31 loc) · 976 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/bin/bash
set -e
echo "=== Deploying Infrastructure ==="
# Change to terraform directory
cd terraform
# Apply terraform
echo "→ Running terraform apply..."
terraform apply -auto-approve
# Go back to root
cd ..
# Wait for SSH to be available
echo "→ Waiting for SSH to be available..."
INSTANCE_IP=$(terraform -chdir=terraform output -raw instance_public_ip)
echo " Instance IP: $INSTANCE_IP"
MAX_RETRIES=30
RETRY_COUNT=0
while ! ssh -o StrictHostKeyChecking=no -o ConnectTimeout=5 ubuntu@$INSTANCE_IP exit 2>/dev/null; do
RETRY_COUNT=$((RETRY_COUNT + 1))
if [ $RETRY_COUNT -ge $MAX_RETRIES ]; then
echo "✗ SSH connection timeout after $MAX_RETRIES attempts"
exit 1
fi
echo " Waiting for SSH... (attempt $RETRY_COUNT/$MAX_RETRIES)"
sleep 10
done
echo "✓ SSH is available"
# Run ansible
echo "→ Running ansible-playbook..."
ansible-playbook -i inventory.ini site.yml
echo "=== Deployment Complete ==="
echo "Instance IP: $INSTANCE_IP"