44 lines
1.7 KiB
Bash
44 lines
1.7 KiB
Bash
#!/bin/bash
|
|
|
|
# ==============================================================================
|
|
# ENVIRONMENT VARIABLES
|
|
# ==============================================================================
|
|
PROXMOX_IP="192.168.1.100" # <--- CHANGE ME
|
|
PROXMOX_USER="root" # <--- CHANGE ME
|
|
# ==============================================================================
|
|
|
|
echo "--- Starting Lead Architect Bootstrap Process ---"
|
|
|
|
# 1. Install Ansible and dependencies
|
|
echo "[1/4] Installing Ansible and Proxmoxer..."
|
|
sudo apt update && sudo apt install -y ansible python3-pip
|
|
pip3 install proxmoxer --break-system-packages 2>/dev/null || pip3 install proxmoxer
|
|
|
|
# 2. Smart SSH Key Check
|
|
# We check for ED25519 first, then RSA.
|
|
if [ -f "$HOME/.ssh/id_ed25519" ]; then
|
|
SSH_KEY_PATH="$HOME/.ssh/id_ed25519"
|
|
echo "[2/4] Found existing ED25519 key at $SSH_KEY_PATH"
|
|
elif [ -f "$HOME/.ssh/id_rsa" ]; then
|
|
SSH_KEY_PATH="$HOME/.ssh/id_rsa"
|
|
echo "[2/4] Found existing RSA key at $SSH_KEY_PATH. Using as fallback."
|
|
else
|
|
SSH_KEY_PATH="$HOME/.ssh/id_ed25519"
|
|
echo "[2/4] No usable keys found. Generating new ED25519 keypair..."
|
|
ssh-keygen -t ed25519 -f "$SSH_KEY_PATH" -N ""
|
|
fi
|
|
|
|
# 3. Transfer Public Key
|
|
# We use the variable determined in the step above
|
|
echo "[3/4] Copying ${SSH_KEY_PATH}.pub to Proxmox ($PROXMOX_IP)..."
|
|
ssh-copy-id -i "${SSH_KEY_PATH}.pub" "${PROXMOX_USER}@${PROXMOX_IP}"
|
|
|
|
# 4. Create Inventory
|
|
echo "[4/4] Generating hosts.ini..."
|
|
cat <<EOF > hosts.ini
|
|
[proxmox_nodes]
|
|
proxmox_server ansible_host=$PROXMOX_IP ansible_user=$PROXMOX_USER ansible_ssh_private_key_file=$SSH_KEY_PATH
|
|
EOF
|
|
|
|
echo "--- Bootstrap Complete ---"
|
|
echo "Verification: ansible proxmox_nodes -m ping -i hosts.ini" |