update: enhance Vagrant setup with new scripts for node and workstation installation, and update provisioning to target specific VMs
This commit is contained in:
parent
5f448d7fc7
commit
aa912d55df
6 changed files with 79 additions and 23 deletions
|
|
@ -1,6 +1,10 @@
|
|||
#!/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.
|
||||
# set -euo pipefail
|
||||
|
||||
# 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
|
||||
|
|
@ -20,8 +24,6 @@ else
|
|||
fi
|
||||
fi
|
||||
|
||||
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
echo "Script directory: $SCRIPT_DIR"
|
||||
|
||||
|
|
@ -39,8 +41,6 @@ if [ -z "$(vagrant status | grep 'running')" ]; then
|
|||
vagrant up
|
||||
fi
|
||||
|
||||
|
||||
|
||||
network_info=()
|
||||
vagrant_ports=()
|
||||
|
||||
|
|
@ -50,12 +50,11 @@ running_vms=$(vagrant status | grep "running" | awk '{print $1}')
|
|||
for vm in $running_vms; do
|
||||
|
||||
# Check network interfaces and get specific IPs
|
||||
vm_ips=$(vagrant ssh "$vm" -c "ip -j addr" | jq -r '.[] |
|
||||
select(.addr_info != null) |
|
||||
vm_ips=$(vagrant ssh "$vm" -c "ip -j addr | jq -r '.[] |
|
||||
select(.ifname==\"enp0s8\") |
|
||||
.addr_info[] |
|
||||
select(.family == "inet" and (.local | startswith("'${VAGRANT_NETWORK_PREFIX:-192.168.56}'."))) |
|
||||
.local')
|
||||
|
||||
select(.family==\"inet\" and .scope==\"global\" and .prefixlen<32 and .local!=\"'${VAGRANT_NETWORK_PREFIX:-192.168.56.250}'\") |
|
||||
.local'")
|
||||
|
||||
# Save the VM's IP to the array if it matches our pattern
|
||||
if [ ! -z "$vm_ips" ]; then
|
||||
|
|
@ -74,11 +73,6 @@ done
|
|||
|
||||
echo "Network information gathered successfully."
|
||||
|
||||
|
||||
# get vagrant ports
|
||||
# echo "Gathering Vagrant port information..."
|
||||
|
||||
|
||||
# Ensure unique ports are added to the vagrant_ports array
|
||||
add_unique_port() {
|
||||
local port=$1
|
||||
|
|
@ -97,13 +91,11 @@ while read -r line; do
|
|||
done < <(vagrant ssh-config | grep Port)
|
||||
|
||||
while read -r line; do
|
||||
|
||||
# Extract the port number
|
||||
port=$(echo "$line" | awk '{print $2}')
|
||||
add_unique_port "$port"
|
||||
done < <(vagrant ssh-config | grep Port)
|
||||
|
||||
|
||||
ips=()
|
||||
# Print network information
|
||||
for info in "${network_info[@]}"; do
|
||||
|
|
|
|||
17
scripts/install_vagrant_nodes.sh
Executable file
17
scripts/install_vagrant_nodes.sh
Executable file
|
|
@ -0,0 +1,17 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
VAGRANT_DIR="$SCRIPT_DIR/../vagrant/dev/ubuntu/"
|
||||
|
||||
echo "Script directory: $SCRIPT_DIR"
|
||||
echo "Vagrant directory: $VAGRANT_DIR"
|
||||
cd "$VAGRANT_DIR" || {
|
||||
echo "Failed to change directory to Vagrant directory: $VAGRANT_DIR"
|
||||
exit 1
|
||||
}
|
||||
|
||||
vagrant up vm1 vm2 vm3
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Failed to start Vagrant VMs. Please check your Vagrant setup."
|
||||
exit 1
|
||||
fi
|
||||
14
scripts/install_vagrant_workstation.sh
Executable file
14
scripts/install_vagrant_workstation.sh
Executable file
|
|
@ -0,0 +1,14 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
VAGRANT_DIR="$SCRIPT_DIR/../vagrant/dev/ubuntu/"
|
||||
|
||||
echo "Script directory: $SCRIPT_DIR"
|
||||
echo "Vagrant directory: $VAGRANT_DIR"
|
||||
cd "$VAGRANT_DIR" || {
|
||||
echo "Failed to change directory to Vagrant directory: $VAGRANT_DIR"
|
||||
exit 1
|
||||
}
|
||||
|
||||
|
||||
vagrant up workstation
|
||||
Loading…
Add table
Add a link
Reference in a new issue