fixed structure

This commit is contained in:
2026-05-17 06:34:17 +05:30
parent 5ce03220d4
commit 59c4b7a949
14 changed files with 433 additions and 3 deletions
+57
View File
@@ -0,0 +1,57 @@
#!/usr/bin/env bash
# One-command deploy: pulumi up → ansible provision
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
echo "=== Step 1: Pulumi — creating Azure infrastructure ==="
cd "$PROJECT_DIR"
pulumi up --yes --stack dev
# grab outputs
VM_IP=$(pulumi stack output vm_public_ip --stack dev)
ADMIN_USER=$(pulumi stack output admin_username --stack dev)
echo ""
echo "VM is up at: $VM_IP"
echo "User: $ADMIN_USER"
echo ""
echo "=== Step 2: Generating Ansible inventory ==="
if [ ! -f "$PROJECT_DIR/ansible/inventory.yml" ]; then
cat > "$PROJECT_DIR/ansible/inventory.yml" <<EOF
all:
hosts:
vps:
ansible_host: ${VM_IP}
ansible_user: ${ADMIN_USER}
EOF
else
# Update the IP without destroying the user's custom variables
sed -i "s/ansible_host: .*/ansible_host: ${VM_IP}/" "$PROJECT_DIR/ansible/inventory.yml"
fi
echo "Inventory written to ansible/inventory.yml"
echo ""
echo "=== Step 3: Waiting for SSH to be ready ==="
MAX_RETRIES=30
for i in $(seq 1 $MAX_RETRIES); do
if ssh -o ConnectTimeout=5 -o StrictHostKeyChecking=no "${ADMIN_USER}@${VM_IP}" "echo ok" &>/dev/null; then
echo "SSH is ready!"
break
fi
echo " waiting for SSH... (attempt $i/$MAX_RETRIES)"
sleep 10
done
echo ""
echo "=== Step 4: Ansible — configuring the VPS ==="
cd "$PROJECT_DIR/ansible"
ansible-playbook playbook.yml
echo ""
echo "=== Done! ==="
echo "SSH in: ssh ${ADMIN_USER}@${VM_IP}"
echo "Next: clone your repos and docker compose up"