added vagrant scripts
This commit is contained in:
parent
6ff4033a13
commit
2997f0252a
2 changed files with 171 additions and 0 deletions
77
scripts/configure_vagrant_k3s.sh
Executable file
77
scripts/configure_vagrant_k3s.sh
Executable file
|
|
@ -0,0 +1,77 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# 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."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if VirtualBox is installed
|
||||
if ! command -v VBoxManage &> /dev/null; then
|
||||
echo "VirtualBox is not installed. Please install VirtualBox to proceed."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
echo "Script directory: $SCRIPT_DIR"
|
||||
|
||||
VAGRANT_DIR="$SCRIPT_DIR/../vagrant/dev/ubuntu/"
|
||||
|
||||
cd "$VAGRANT_DIR" || {
|
||||
echo "Failed to change directory to Vagrant directory: $VAGRANT_DIR"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Check if any VMs are running; if not, run 'vagrant up'
|
||||
if [ -z "$(vagrant status | grep 'running')" ]; then
|
||||
echo "No Vagrant VMs are running. Starting VMs with 'vagrant up'..."
|
||||
vagrant up
|
||||
fi
|
||||
|
||||
network_info=()
|
||||
|
||||
echo "Gathering network information from running VMs..."
|
||||
running_vms=$(vagrant status | grep "running" | awk '{print $1}')
|
||||
|
||||
for vm in $running_vms; do
|
||||
|
||||
# Check network interfaces
|
||||
vm_info=$(vagrant ssh "$vm" -c "ip -j addr" | jq -r '
|
||||
.[] |
|
||||
"Interface: \(.ifname)\n" + vm_info=$(vagrant ssh "$vm" -c "ip -j addr" | jq -r '
|
||||
|
||||
(if .addr_info then
|
||||
(.addr_info | map(" IP (\(.family)): \(.local)") | join("\n"))
|
||||
else
|
||||
""
|
||||
end)
|
||||
')
|
||||
|
||||
# Save the VM's network info to the array
|
||||
network_info+=("$vm:\n$vm_info")
|
||||
|
||||
done
|
||||
|
||||
for vm in $running_vms; do
|
||||
echo $vm
|
||||
echo "----------------------------------------"
|
||||
vagrant ssh "$vm" -c "free" | grep 'Mem:' | awk '{print "Memory in bytes: " $2 " Memory in MB: " $2/1024/1024}'
|
||||
vagrant ssh "$vm" -c "lscpu" | grep 'CPU(s):' | grep -v 'NUMA' | awk '{print "CPU count: " $2}'
|
||||
echo "----------------------------------------"
|
||||
done
|
||||
|
||||
echo "Network information gathered successfully."
|
||||
|
||||
# Print network information
|
||||
for info in "${network_info[@]}"; do
|
||||
echo "----------------------------------------"
|
||||
echo -e "$info"
|
||||
echo "----------------------------------------"
|
||||
done
|
||||
|
||||
|
||||
|
||||
94
vagrant/dev/ubuntu/Vagrantfile
vendored
Normal file
94
vagrant/dev/ubuntu/Vagrantfile
vendored
Normal file
|
|
@ -0,0 +1,94 @@
|
|||
# -*- mode: ruby -*-
|
||||
# vi: set ft=ruby :
|
||||
|
||||
# All Vagrant configuration is done below. The "2" in Vagrant.configure
|
||||
# configures the configuration version (we support older styles for
|
||||
# backwards compatibility). Please don't change it unless you know what
|
||||
# you're doing.
|
||||
Vagrant.configure("2") do |config|
|
||||
# VM 1 Configuration
|
||||
config.vm.define "vm1" do |vm1|
|
||||
vm1.vm.box = "hashicorp/bionic64"
|
||||
|
||||
# run ip link to list network interfaces on linux
|
||||
# run ipconfig to list network interfaces on Windows
|
||||
# Example output:
|
||||
# Ethernet adapter vEthernet (WSL):
|
||||
# Connection-specific DNS Suffix . :
|
||||
# IPv6 Address. . . . . . . . . . . : fe80::xxxx:xxxx:xxxx:xxxx%xx
|
||||
# IPv4 Address. . . . . . . . . . . : 192.168.x.x
|
||||
# Subnet Mask . . . . . . . . . . . :
|
||||
# on macOS, run ifconfig to list network interfaces
|
||||
# Example output:
|
||||
# en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
|
||||
# options=400<LINKSTATE>
|
||||
# ether xx:xx:xx:xx:xx:xx
|
||||
# inet6 fe80::xxxx:xxxx:xxxx:xxxx%en0 prefixlen 64 scopeid 0x4
|
||||
# inet 192.168.x.x netmask 0xffffff00 broadcast 192.168.x.255
|
||||
|
||||
# This configuration sets up a private network for inter-VM communication
|
||||
# and a public network for external access.
|
||||
# The private network uses DHCP to assign IP addresses automatically.
|
||||
# Private network for inter-VM communication using DHCP
|
||||
|
||||
# Uncomment the following line to use a specific network interface for the public network
|
||||
# and replace "wlp0s20f3" with your actual network interface name.
|
||||
# vm1.vm.network "public_network", bridge: "wlp0s20f3"
|
||||
|
||||
vm1.vm.network "private_network", type: "dhcp"
|
||||
|
||||
vm1.vm.provider "virtualbox" do |vb|
|
||||
vb.memory = "2048" # 2GB memory
|
||||
vb.cpus = 2
|
||||
end
|
||||
|
||||
vm1.vm.provision "shell", inline: <<-SHELL
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y jq
|
||||
SHELL
|
||||
end
|
||||
|
||||
# VM 2 Configuration
|
||||
config.vm.define "vm2" do |vm2|
|
||||
vm2.vm.box = "hashicorp/bionic64"
|
||||
|
||||
# Private network for inter-VM communication using DHCP
|
||||
vm2.vm.network "private_network", type: "dhcp"
|
||||
|
||||
# Public network for external access
|
||||
vm2.vm.network "public_network", bridge: "wlp0s20f3"
|
||||
|
||||
vm2.vm.provider "virtualbox" do |vb|
|
||||
vb.memory = "2048" # 2GB memory
|
||||
vb.cpus = 2
|
||||
end
|
||||
|
||||
vm2.vm.provision "shell", inline: <<-SHELL
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y jq
|
||||
SHELL
|
||||
end
|
||||
|
||||
# VM 3 Configuration
|
||||
config.vm.define "vm3" do |vm3|
|
||||
vm3.vm.box = "hashicorp/bionic64"
|
||||
|
||||
# Private network for inter-VM communication using DHCP
|
||||
vm3.vm.network "private_network", type: "dhcp"
|
||||
|
||||
# Public network for external access
|
||||
vm3.vm.network "public_network", bridge: "wlp0s20f3"
|
||||
|
||||
vm3.vm.provider "virtualbox" do |vb|
|
||||
vb.memory = "2048" # 2GB memory
|
||||
vb.cpus = 2
|
||||
end
|
||||
|
||||
vm3.vm.provision "shell", inline: <<-SHELL
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y jq
|
||||
SHELL
|
||||
|
||||
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue