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

# Files
while true; do
    read -p "Enter the path to the hosts file: " NODES_FILE
    if [[ -f "$NODES_FILE" ]]; then
        echo "Hosts file found: $NODES_FILE"
        break
    else
        echo "Error: The file does not exist at the specified path. Please enter a valid path."
    fi
done


while true; do
    read -p "Enter the path to the package file: " PACKAGES_FILE
    if [[ -f "$PACKAGES_FILE" ]]; then
        echo "Package file found: $PACKAGES_FILE"
        break
    else
        echo "Error: The file does not exist at the specified path. Please enter a valid path."
    fi
done

# User SSH root
USER="root"
read -sp "Enter the root password for the hosts: " ROOT_PASS
echo

# Repositories PVE
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 or 2): " REPO_OPTION

# Repositories CEPH
echo "Which version of Ceph do you want to use?"
echo "1) Ceph Reef"
echo "2) Ceph Quincy"
read -p "Choose an option (1 or 2): " CEPH_VERSION

# Definición de repositorios Proxmox para 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"

# Definir repositorios para Bookworm en función de la versión seleccionada
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"

# Command to install packages
INSTALL_CMD="apt-get update && apt-get install -y expect ${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" "\
            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 and $hostname ($ip)..."
        sshpass -p "$ROOT_PASS" ssh -o StrictHostKeyChecking=no "$USER@$ip" "\
            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  # Skip empty lines
    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

instalar paquetes proxmox de forma masiva

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.

FAQS

Proxmox is free and open source, but offers four types of subscription (Community, Basic, Standard and Premium) for access to stable repositories and official technical support. Without a subscription you have everything Proxmox offers, there is no limitation and you can use the “no-subscription” or “test” repositories.

If you don’t have a subscription, you can switch your repositories to use the “no-subscription” channel. You can do this from the Proxmox web interface or via the console as on any Debian system.

It is not recommended for production environments, but we can use 2 nodes by adding a qdevice that can even be on a raspberry.

A QDevice (Quorum Device) is a witness installed on a virtual machine or physical device that is used in a Proxmox VE cluster to help avoid quorum issues when you have only two nodes. It is necessary to install corosync-qnetd on the device and on all two nodes in the cluster. Once installed from any node we run pvecm qdevice ip_qdevice.

Deja tu comentario

Your email address will not be published. Required fields are marked *

Últimos artículos

seguridad de datos

Zextras Carbonio CE

ZEXTRAS CARBONIO COMMUNITY EDITION, YOUR DATA, YOUR CONTROL We live in a world where data

Más visitados