update: add installation scripts for Vagrant and Ansible, enhance k3s setup, and improve provisioning process

This commit is contained in:
jon brookes 2025-08-07 19:08:46 +01:00
parent ff55197c58
commit 514e05a1f6
5 changed files with 103 additions and 22 deletions

View file

@ -3,7 +3,6 @@
# This script checks for Vagrant and VirtualBox prerequisites, ensures Vagrant VMs are running, and gathers network and system information from the VMs.
echo "Checking Vagrant prerequisites..."
# Check if Vagrant is installed
if ! command -v vagrant &> /dev/null; then
echo "Vagrant is not installed. Please install Vagrant to proceed."
@ -21,6 +20,8 @@ else
fi
fi
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
echo "Script directory: $SCRIPT_DIR"
@ -38,6 +39,8 @@ if [ -z "$(vagrant status | grep 'running')" ]; then
vagrant up
fi
network_info=()
vagrant_ports=()
@ -112,32 +115,30 @@ for info in "${network_info[@]}"; do
done
# Print Vagrant ports
echo "Vagrant Ports:"
for port in "${vagrant_ports[@]}"; do
echo "Port: $port"
done
echo "Creating Ansible inventory file..."
ANSIBLE_DIR="$VAGRANT_DIR/ansible"
mkdir -p "$ANSIBLE_DIR"
INVENTORY_FILE="$ANSIBLE_DIR/ansible_inventory.ini"
INVENTORY_FILE="ansible/ansible_inventory.ini"
echo "Ansible inventory file: $INVENTORY_FILE"
echo "[all]" > "$INVENTORY_FILE"
i=0
for info in "${network_info[@]}"; do
port="22"
vm=$(echo "$info" | cut -d':' -f1)
host_ip=$(echo "$info" | cut -d':' -f2)
echo "$vm ansible_host=$host_ip ansible_port=$port ansible_user=vagrant ansible_ssh_private_key_file=.vagrant/machines/$vm/virtualbox/private_key ansible_python_interpreter=/usr/bin/python3" >> "$INVENTORY_FILE"
echo "$vm ansible_host=$host_ip ansible_port=$port ansible_user=vagrant ansible_ssh_private_key_file=~/.ssh/${vm}_key ansible_python_interpreter=/usr/bin/python3" >> "$INVENTORY_FILE"
((i++))
done
echo "" >> "$INVENTORY_FILE"
echo "[vms]" >> "$INVENTORY_FILE"
for vm in $running_vms; do
echo $vm >> "$INVENTORY_FILE"
if [[ "$vm" == *"vm"* ]]; then
echo $vm >> "$INVENTORY_FILE"
# vm=$(echo "$vm" | sed 's/vm//')
fi
done
echo "Ansible inventory file created at: $INVENTORY_FILE"
# source venv ansible
fi