Installing packages in Proxmox 8 in bulk
INSTALLING PACKAGES IN PROXMOX 8 IN BULK
This is a Christmas gift for all those Proxmox enthusiasts or those who are recently getting to know it because it is the best alternative after VMware was purchased by Broadcom. We have been a Proxmox partner for many years and we encourage you to take the step if you have not done so yet.
With this script you can install the packages you need in your cluster or on independent nodes as long as they have the same password without having to go node by node.
The operation is simple, on our machine or machine where we run the script we need 3 things:
Install sshpass
apt-get install sshpass
A text file with the name and IP of the nodes one by line
PVE1 192.168.1.250
PVE2 192.168.1.251
PVE3 192.168.1.252
A text file with the packages to install, one per line
telnet
net-tools
With this we create our install-packets.sh script by pasting the following code:
#!/bin/bash
#by TL
# Request node file and verify that it exists
while true; do
read -p "Enter the path to the nodes file: " NODES_FILE
if [[ -f "$NODES_FILE" ]]; then
break
else
echo "Error: The node file does not exist at the specified path. Please enter a valid path."
fi
done
# Request package file and verify that it exists
while true; do
read -p "Enter the path to the package file: " PACKAGES_FILE
if [[ -f "$PACKAGES_FILE" ]]; then
break
else
echo "Error: The package file does not exist at the specified path. Please enter a valid path."
fi
done
# SSH user and password to connect to the nodes
USER="root"
read -sp "Enter the root password for the nodes: " ROOT_PASS
echo
# Proxmox Repository Type
echo "Do you want to use the Enterprise or No-Subscription repositories for Proxmox?"
echo "1) Enterprise"
echo "2) No-Subscription"
read -p "Choose an option (1 o 2): " REPO_OPTION
# Ask for Ceph version
echo "Which version of Ceph do you want to use?"
echo "1) Ceph Reef"
echo "2) Ceph Quincy"
read -p "Choose an option (1 o 2): " CEPH_VERSION
# Defining Proxmox repositories for Bookworm
NOSUB_REPO="deb http://download.proxmox.com/debian/pve bookworm pve-no-subscription"
ENTERPRISE_REPO="deb https://enterprise.proxmox.com/debian/pve bookworm pve-enterprise"
# Define Ceph repositories for Bookworm based on the selected version
if [[ "$CEPH_VERSION" -eq 1 ]]; then
if [[ "$REPO_OPTION" -eq 1 ]]; then
CEPH_REPO="deb https://enterprise.proxmox.com/debian/ceph-reef bookworm enterprise"
else
CEPH_REPO="deb http://download.proxmox.com/debian/ceph-reef bookworm no-subscription"
fi
elif [[ "$CEPH_VERSION" -eq 2 ]]; then
if [[ "$REPO_OPTION" -eq 1 ]]; then
CEPH_REPO="deb https://enterprise.proxmox.com/debian/ceph-quincy bookworm enterprise"
else
CEPH_REPO="deb http://download.proxmox.com/debian/ceph-quincy bookworm no-subscription"
fi
else
echo "Invalid Ceph version option. Exiting..."
exit 1
fi
# Read the list of packages from the provided file
PACKAGES=()
while IFS= read -r package; do
PACKAGES+=("$package")
done < "$PACKAGES_FILE"
# Installing the packages
INSTALL_CMD="apt-get update && apt-get install -y ${PACKAGES[@]}"
# Function to process each node
process_node() {
local hostname=$1
local ip=$2
echo "Connecting to $hostname ($ip)..."
if [[ "$REPO_OPTION" -eq 1 ]]; then
echo "Switching to Enterprise Repositories in $hostname ($ip)..."
sshpass -p "$ROOT_PASS" ssh -o StrictHostKeyChecking=no "$USER@$ip" "\
sed -i '/deb http:\/\/download.proxmox.com\/debian\/pve bookworm pve-no-subscription/d' /etc/apt/sources.list; \
rm -f /etc/apt/sources.list.d/pve-no-subscription.list; \
rm -f /etc/apt/sources.list.d/ceph.list; \
echo '$ENTERPRISE_REPO' > /etc/apt/sources.list.d/pve-enterprise.list; \
echo '$CEPH_REPO' > /etc/apt/sources.list.d/ceph.list; \
apt-get update" &
else
echo "Switching to No-Subscription Repositories in $hostname ($ip)..."
sshpass -p "$ROOT_PASS" ssh -o StrictHostKeyChecking=no "$USER@$ip" "\
sed -i '/deb http:\/\/download.proxmox.com\/debian\/pve bookworm pve-no-subscription/d' /etc/apt/sources.list; \
rm -f /etc/apt/sources.list.d/pve-enterprise.list; \
rm -f /etc/apt/sources.list.d/ceph.list; \
echo '$NOSUB_REPO' > /etc/apt/sources.list.d/pve-no-subscription.list; \
echo '$CEPH_REPO' > /etc/apt/sources.list.d/ceph.list; \
apt-get update" &
fi
# Wait a few seconds to make sure the changes are applied.
sleep 5
# Installing the packages
echo "Installing packages on $hostname ($ip)..."
sshpass -p "$ROOT_PASS" ssh -o StrictHostKeyChecking=no "$USER@$ip" "$INSTALL_CMD"
}
# Read the node file and process each node in parallel
while IFS=' ' read -r hostname ip; do
[[ -z "$hostname" || -z "$ip" ]] && continue
process_node "$hostname" "$ip" &
done < "$NODES_FILE"
# Wait for all background processes to finish
wait
echo "Completion of the process."
We give it permissions with chmod +x install-packets.sh and run it ./install-packets.sh obtaining the following output
It is a very versatile script that you can adapt to other versions of Proxmox or other systems.
Test it in a lab first to understand how it works.
Happy holidays.
Thank you for reading our posts.
No hay comentarios