Initial Lab Setup
This commit is contained in:
Executable
+28
@@ -0,0 +1,28 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Usage: ./bootstrap_node.sh <IP_ADDRESS> <NEW_HOSTNAME> <REMOTE_USER>
|
||||
IP=$1
|
||||
NEW_HOSTNAME=$2
|
||||
R_USER=${3:-pi} # Defaults to 'pi' if not specified
|
||||
|
||||
echo "🚀 Bootstrapping $NEW_HOSTNAME at $IP..."
|
||||
|
||||
# 1. Push SSH Keys (Mac -> Node)
|
||||
# This removes the need for passwords immediately
|
||||
ssh-copy-id -i ~/.ssh/id_ed25519.pub "$R_USER@$IP"
|
||||
|
||||
# 2. Set Hostname and Passwordless Sudo
|
||||
# We use a single SSH command to minimize login prompts
|
||||
ssh -t "$R_USER@$IP" << EOF
|
||||
sudo hostnamectl set-hostname $NEW_HOSTNAME
|
||||
echo "$R_USER ALL=(ALL) NOPASSWD:ALL" | sudo tee /etc/sudoers.d/010-$R_USER-nopasswd
|
||||
sudo apt update && sudo apt install -y python3
|
||||
EOF
|
||||
|
||||
echo "✅ $NEW_HOSTNAME is ready for Ansible!"
|
||||
|
||||
# Append to inventory if not already there
|
||||
if ! grep -q "$NEW_HOSTNAME" inventory.ini; then
|
||||
echo "$NEW_HOSTNAME ansible_host=$IP" >> inventory.ini
|
||||
echo "Added $NEW_HOSTNAME to inventory.ini"
|
||||
fi
|
||||
Reference in New Issue
Block a user