Última actividad 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.

Revisión 320d44b68c0176836aa835a019a979e888961f5e

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