#!/bin/bash # Add Host 'im' to Ansible Management # Target: 192.168.12.3 (different subnet) # Run this on the control server (CT 127) set -e HOST_ALIAS="im" HOST_IP="192.168.12.3" HOST_USER="maddox" HOST_PORT="22" echo "=== Adding Host '$HOST_ALIAS' to Ansible Management ===" echo "IP: $HOST_IP" echo "User: $HOST_USER" echo "" # ============================================ # 1. Add to ~/.ssh/config # ============================================ if grep -q "^Host $HOST_ALIAS$" ~/.ssh/config 2>/dev/null; then echo "⚠️ Host '$HOST_ALIAS' already exists in ~/.ssh/config - skipping" else cat >> ~/.ssh/config << EOF Host $HOST_ALIAS HostName $HOST_IP User $HOST_USER EOF echo "✅ Added '$HOST_ALIAS' to ~/.ssh/config" fi # ============================================ # 2. Add to tmux-hosts.conf (if exists) # ============================================ if [ -f ~/.ssh/tmux-hosts.conf ]; then if grep -q "^$HOST_ALIAS$" ~/.ssh/tmux-hosts.conf 2>/dev/null; then echo "⚠️ Host '$HOST_ALIAS' already in tmux-hosts.conf - skipping" else echo "$HOST_ALIAS" >> ~/.ssh/tmux-hosts.conf echo "✅ Added '$HOST_ALIAS' to tmux-hosts.conf" fi else echo "ℹ️ No tmux-hosts.conf found - skipping" fi # ============================================ # 3. Create inventory snippet # ============================================ INVENTORY_FILE=~/clustered-fucks/inventory/hosts.yml echo "" echo "============================================" echo "=== Ansible Inventory Update Required ===" echo "============================================" echo "" echo "Add the following to $INVENTORY_FILE" echo "" echo "Under 'docker_hosts > hosts:' section:" echo "----------------------------------------" cat << 'EOF' im: ansible_host: 192.168.12.3 ansible_user: maddox docker_appdata: /volume1/docker EOF echo "----------------------------------------" echo "" echo "Make sure 'im' is also included in these groups:" echo " - all_managed (children section)" echo "" # ============================================ # 4. Test SSH connectivity # ============================================ echo "============================================" echo "=== Testing SSH Connectivity ===" echo "============================================" echo "" echo "Attempting: ssh -o ConnectTimeout=5 -o BatchMode=yes $HOST_ALIAS 'echo OK'" echo "" if ssh -o ConnectTimeout=5 -o BatchMode=yes $HOST_ALIAS 'echo OK' 2>/dev/null; then echo "✅ SSH connection successful (key already authorized)" else echo "⚠️ SSH key not authorized or host unreachable" echo "" echo "To copy your SSH key, run:" echo " ssh-copy-id $HOST_ALIAS" echo "" echo "If host is unreachable, verify:" echo " - Host is powered on" echo " - IP $HOST_IP is correct" echo " - Routing exists to 192.168.12.x subnet" echo " - SSH service is running on target" fi echo "" echo "============================================" echo "=== Next Steps ===" echo "============================================" echo "" echo "1. COPY SSH KEY (if needed):" echo " ssh-copy-id $HOST_ALIAS" echo "" echo "2. EDIT ANSIBLE INVENTORY:" echo " vim ~/clustered-fucks/inventory/hosts.yml" echo " # Add the YAML snippet shown above" echo "" echo "3. TEST ANSIBLE CONNECTION:" echo " cd ~/clustered-fucks" echo " ansible $HOST_ALIAS -m ping" echo "" echo "4. VERIFY GROUP MEMBERSHIP:" echo " ansible-inventory --graph" echo "" echo "5. COMMIT TO GIT:" echo " cd ~/clustered-fucks" echo " git add -A && git commit -m 'Add host im (192.168.12.3) to inventory' && git push" echo "" echo "============================================" echo "Done! Host '$HOST_ALIAS' added to SSH config." echo "Remember to manually update the Ansible inventory." echo "============================================"