Utoljára aktív 3 weeks ago

Working version of my proxmox template creation script. It'll be used to provision Packer with necessary templates in order to build it's image.

Revízió ec51f33763e9d5c2a38fe2c09521e94ab2dd95e2

create-pve-template.sh Eredeti
1#!/bin/bash
2set -e
3
4TEMPLATE_URL="https://cloud-images.ubuntu.com/plucky/current/plucky-server-cloudimg-amd64.img"
5VMID=9000
6TEMPLATE_NAME="ubuntu-25.04-cloudimg-temp"
7STORAGE="local-lvm"
8SSH_KEYS=$(curl -s https://gist.vorpax.dev/vorpax/ssh/raw/HEAD/ssh-keys.pub)
9
10# positional args first (optional)
11[ -n "$1" ] && VMID="$1"
12[ -n "$2" ] && TEMPLATE_NAME="$2"
13[ -n "$3" ] && STORAGE="$3"
14
15# overrides (still optional)
16while [[ $# -gt 3 ]]; do
17 shift
18 case "$1" in
19 --vmid=*) VMID="${1#*=}" ;;
20 --template=*) TEMPLATE_NAME="${1#*=}" ;;
21 --storage=*) STORAGE="${1#*=}" ;;
22 esac
23done
24
25cd /tmp
26wget -O "${TEMPLATE_NAME}_disk" \
27 "$TEMPLATE_URL"
28
29qm create "$VMID" \
30 --name "$TEMPLATE_NAME" \
31 --memory 3072 \
32 --cores 3 \
33 --net0 virtio,bridge=vmbr0 \
34 --serial0 socket \
35 --vga serial0
36
37qm importdisk "$VMID" "${TEMPLATE_NAME}_disk" "$STORAGE"
38
39mkdir -p ssh_keys_tmp
40
41
42SSH_KEYS_ARGS=""
43while IFS= read -r key; do
44 [ -z "$key" ] && continue
45 SSH_KEYS_ARGS+=" --sshkeys $key"
46done <<< "$SSH_KEYS"
47
48qm set "$VMID" \
49 --scsihw virtio-scsi-pci \
50 --scsi0 "${STORAGE}:vm-${VMID}-disk-0" \
51 --ide2 "${STORAGE}:cloudinit" \
52 --boot c --bootdisk scsi0 \
53 --serial0 socket --vga serial0 \
54 --net0 virtio,bridge=vmbr0 \
55 --ciuser packer \
56 --searchdomain example.com \
57 $SSH_KEYS_ARGS
58
59qm template "$VMID"
60
61echo "Template $VMID ready for Packer"