4
0
proxmox-scripts/vm/create_from_template.sh
2024-05-11 20:30:37 +02:00

30 lines
687 B
Bash

#!/bin/bash
INPUT_FILE=$1
if [ -z "$INPUT_FILE" ]; then
echo "Usage: $0 <path-to-input-file>"
echo "Input file format:"
echo -e "\tusername pool_name"
echo -e "\tusername pool_name"
echo -e "\t..."
exit 1
fi
NEXT_VM_ID=202404101
TEMPLATE_VM_ID=202404001
while read -r line; do
USERNAME=$(echo "$line" | awk '{print $1}')
POOL_NAME=$(echo "$line" | awk '{print $2}')
echo "Creating VM for $USERNAME ($POOL_NAME)"
qm clone $TEMPLATE_VM_ID $NEXT_VM_ID --name "$USERNAME" --full false --pool $POOL_NAME
pvesh set /access/acl --path /vms/$NEXT_VM_ID --roles PVEVMUser --users "$USERNAME@arda.lan"
((NEXT_VM_ID++))
done < "$INPUT_FILE"