Skip to content

Commit ec8a8b1

Browse files
authored
add optional Cloud-init support to Debian VM script (#5137)
* Edit Debian VM script to use Cloud-init * Edit Debian VM page to point to Cloud-init guide * Revert "Edit Debian VM page to point to Cloud-init guide" This reverts commit 3f99b2d. * Edit Debian VM script to ask for cloud-init
1 parent d850dde commit ec8a8b1

File tree

1 file changed

+30
-6
lines changed

1 file changed

+30
-6
lines changed

vm/debian-vm.sh

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ MACADDRESS="${TAB}🔗${TAB}${CL}"
5757
VLANTAG="${TAB}🏷️${TAB}${CL}"
5858
CREATING="${TAB}🚀${TAB}${CL}"
5959
ADVANCED="${TAB}🧩${TAB}${CL}"
60+
CLOUD="${TAB}☁️${TAB}${CL}"
6061

6162
THIN="discard=on,ssd=1,"
6263
set -e
@@ -191,6 +192,7 @@ function default_settings() {
191192
VLAN=""
192193
MTU=""
193194
START_VM="yes"
195+
CLOUD_INIT="no"
194196
METHOD="default"
195197
echo -e "${CONTAINERID}${BOLD}${DGN}Virtual Machine ID: ${BGN}${VMID}${CL}"
196198
echo -e "${CONTAINERTYPE}${BOLD}${DGN}Machine Type: ${BGN}i440fx${CL}"
@@ -204,6 +206,7 @@ function default_settings() {
204206
echo -e "${MACADDRESS}${BOLD}${DGN}MAC Address: ${BGN}${MAC}${CL}"
205207
echo -e "${VLANTAG}${BOLD}${DGN}VLAN: ${BGN}Default${CL}"
206208
echo -e "${DEFAULT}${BOLD}${DGN}Interface MTU Size: ${BGN}Default${CL}"
209+
echo -e "${CLOUD}${BOLD}${DGN}Configure Cloud-init: ${BGN}no${CL}"
207210
echo -e "${GATEWAY}${BOLD}${DGN}Start VM when completed: ${BGN}yes${CL}"
208211
echo -e "${CREATING}${BOLD}${DGN}Creating a Debian 12 VM using the above default settings${CL}"
209212
}
@@ -373,6 +376,14 @@ function advanced_settings() {
373376
exit-script
374377
fi
375378

379+
if (whiptail --backtitle "Proxmox VE Helper Scripts" --title "CLOUD-INIT" --yesno "Configure the VM with Cloud-init?" --defaultno 10 58); then
380+
echo -e "${CLOUD}${BOLD}${DGN}Configure Cloud-init: ${BGN}yes${CL}"
381+
CLOUD_INIT="yes"
382+
else
383+
echo -e "${CLOUD}${BOLD}${DGN}Configure Cloud-init: ${BGN}no${CL}"
384+
CLOUD_INIT="no"
385+
fi
386+
376387
if (whiptail --backtitle "Proxmox VE Helper Scripts" --title "START VIRTUAL MACHINE" --yesno "Start VM when completed?" 10 58); then
377388
echo -e "${GATEWAY}${BOLD}${DGN}Start VM when completed: ${BGN}yes${CL}"
378389
START_VM="yes"
@@ -439,7 +450,11 @@ fi
439450
msg_ok "Using ${CL}${BL}$STORAGE${CL} ${GN}for Storage Location."
440451
msg_ok "Virtual Machine ID is ${CL}${BL}$VMID${CL}."
441452
msg_info "Retrieving the URL for the Debian 12 Qcow2 Disk Image"
442-
URL=https://cloud.debian.org/images/cloud/bookworm/latest/debian-12-nocloud-amd64.qcow2
453+
if [ "$CLOUD_INIT" == "yes" ]; then
454+
URL=https://cloud.debian.org/images/cloud/bookworm/latest/debian-12-genericcloud-amd64.qcow2
455+
else
456+
URL=https://cloud.debian.org/images/cloud/bookworm/latest/debian-12-nocloud-amd64.qcow2
457+
fi
443458
sleep 2
444459
msg_ok "${CL}${BL}${URL}${CL}"
445460
curl -f#SL -o "$(basename "$URL")" "$URL"
@@ -474,11 +489,20 @@ qm create $VMID -agent 1${MACHINE} -tablet 0 -localtime 1 -bios ovmf${CPU_TYPE}
474489
-name $HN -tags community-script -net0 virtio,bridge=$BRG,macaddr=$MAC$VLAN$MTU -onboot 1 -ostype l26 -scsihw virtio-scsi-pci
475490
pvesm alloc $STORAGE $VMID $DISK0 4M 1>&/dev/null
476491
qm importdisk $VMID ${FILE} $STORAGE ${DISK_IMPORT:-} 1>&/dev/null
477-
qm set $VMID \
478-
-efidisk0 ${DISK0_REF}${FORMAT} \
479-
-scsi0 ${DISK1_REF},${DISK_CACHE}${THIN}size=${DISK_SIZE} \
480-
-boot order=scsi0 \
481-
-serial0 socket >/dev/null
492+
if [ "$CLOUD_INIT" == "yes" ]; then
493+
qm set $VMID \
494+
-efidisk0 ${DISK0_REF}${FORMAT} \
495+
-scsi0 ${DISK1_REF},${DISK_CACHE}${THIN}size=${DISK_SIZE} \
496+
-scsi1 ${STORAGE}:cloudinit \
497+
-boot order=scsi0 \
498+
-serial0 socket >/dev/null
499+
else
500+
qm set $VMID \
501+
-efidisk0 ${DISK0_REF}${FORMAT} \
502+
-scsi0 ${DISK1_REF},${DISK_CACHE}${THIN}size=${DISK_SIZE} \
503+
-boot order=scsi0 \
504+
-serial0 socket >/dev/null
505+
fi
482506
DESCRIPTION=$(
483507
cat <<EOF
484508
<div align='center'>

0 commit comments

Comments
 (0)