create-ubuntu-cloud-template: fix snippet logins, failure cleanup and profile bugs - #27
Merged
Merged
Conversation
… and profile bugs Attach the snippet as vendor-data instead of user-data, so clones keep the Proxmox user, password, SSH keys and hostname. Run cleanup on every failure (set -E plus an EXIT trap). Keep SNIPPETS_STOR and the template name from the profile. Keep safety flags command-line only. Use import-from for the disk, check VM IDs cluster-wide, validate SSH keys, merge the virt-customize calls, and restructure comments and help for readability.
Stop protecting the VM on exit before cleanup runs, so a failure or Ctrl+C at the final prompt no longer destroys the finished template. chmod 600 profiles after writing, since umask only affects new files. Write the VM notes after the snippet step so they match what was attached. Hide plain iSCSI storages, which cannot allocate new disks.
…te confirm Clear SNIPPETS_STOR when the user declines the snippet, so later unattended runs don't re-enable it. Confirm overwrite of an unnamed VM by its ID, so an empty Enter can no longer match an empty name.
…he image is ready Confirm the overwrite early but destroy the old template only just before create_vm, re-running the safety checks. Cancelling at the summary, or a failed download or customise, no longer leaves you with no template. Also strip spaces from package lists written by older profiles.
…bers as base 10 Reject invalid template names and tags before any work starts, so qm create can no longer fail after a long download or after --force-overwrite has destroyed the old template. Parse numeric input as base 10 so 08/09 no longer error and 010 is not read as octal. Correct the comment about GitHub key references.
Map codenames to version numbers using Ubuntu's meta-release lists, sort the menu by version, and flag LTS, end-of-life, Ubuntu Pro-only and development releases. Falls back to plain codenames if the lists can't be fetched. OS_NAME now reads e.g. 'Ubuntu 24.04 LTS (Noble)'.
SSH keys from the Cloud-Init tab and root disk growth already work without the snippet, so stop implying otherwise. Drop the redundant growpart block, only enable ssh_pwauth when no SSH key was set, and word the prompt and VM notes to match. List cloud-init in VIRT_PKGS as a safeguard.
…ox ciupgrade Add a CI_UPGRADE setting (prompted, saved in profiles, default off) that sets Proxmox's 'Upgrade packages' cloud-init option, so upgrades are visible and changeable per VM in the GUI. Remove package_update/upgrade from the snippet, which is now an optional place for your own first-boot config (plus password login when no SSH key is set).
…nce header Ask for cores and memory with sensible defaults and host limits, ask for sockets on NUMA hosts (NUMA on when sockets > 1), and make ballooning a yes/no with a minimum. Values are saved to profiles and checked in unattended runs. Use cache=none for all ZFS storage types. Add author, MIT licence, repo and support links to the header.
…ofile values, follow qm docs Ask for the bridge from the ones on this host (the default vmbr1 doesn't exist on most installs, which left clones unable to start), and default to vmbr0. Check NET_BRIDGE, VLAN and DISK_SIZE from profiles before any work, so they can't fail after an overwrite destroyed the old template. Allocate the EFI disk with the documented STORAGE:1 form instead of STORAGE:0,size=1M. Keep the optional release lookup to one quick try, base the VM notes on the snippet file actually attached, and warn that snippet storage must be reachable from every cluster node.
An empty value or a plain NIC such as eth0 passed the existence check. Check membership in the host's bridge list instead.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes several bugs in
create-ubuntu-cloud-template.sh, makes it faster and safer, and restructures the comments and help text so they're easier to scan (AuDHD-friendly).Bug fixes
user=broke logins on clones. In Proxmox, custom user-data replaces the generated user-data (confirmed inPVE/QemuServer/Cloudinit.pm), so clones lost the user, password, SSH keys and hostname. It is now attached asvendor=, which merges with the Cloud-Init tab.set -Ethe ERR trap isn't inherited, so failures left half-built VMs behind. An EXIT trap now handles errors,dieand Ctrl+C.--force-overwritedestroyed the old template first. It was destroyed before the summary prompt and before the download, so cancelling or a failed download left you with no template. You now confirm early, but the destroy happens only just beforeqm create, after the safety checks run again.ubuntu_noble) or a bad tag was only rejected byqm create, after the download or after the old template was destroyed. Both are now checked up front.SNIPPETS_STORfrom the profile was reset to empty after loading, so snippets never worked in unattended runs. Declining the snippet interactively now also clears it from the profile._set_distro_vars.FORCE_OVERWRITE/UNATTENDED/I_KNOW, which broke the "command line only" guarantee.vm-ID-disk-0, which could attach an old leftover disk. The disk now usesimport-from.qm list, which misses containers and VMs on other nodes. It now reads/etc/pve/.vmlist.08or010are now read as base 10, not octal.curl, git, as saved by the old script) are now handled.Improvements
CPU and memory are now asked for instead of being fixed in the script:
balloon=0.SOCKETS,CORES,MEM,BALLOON) and checked before unattended runs. They appear in the summary and the VM notes.Network bridge is now asked for, from the bridges on the host (Linux bridges, SDN vnets,
vmbr*Open vSwitch bridges). Before, it was fixed atvmbr1, which doesn't exist on most installs. Proxmox only checks the bridge when a VM starts, so every clone would have failed to boot. The script default is nowvmbr0.Checked against the Proxmox docs:
qm/pvesmoption matches theqm(1)manual, theqemu-serverDrive.pmschema and the Cloud-Init wiki.STORAGE:1,efitype=4m,...form instead ofSTORAGE:0,...,size=1M.STORAGE:0is only forimport-from, and the EFI size is ignored.Disk cache:
nonefor all ZFS storage types (zfspooland ZFS over iSCSI),writethroughfor everything else. It's shown in the summary and the VM notes.Header: author, MIT licence (Copyright (c) 2026 Alex Lane), SPDX identifier, and repo, latest-version, issues and support links, so a copy shared outside the repo still points home.
The Ubuntu menu shows version numbers. It is sorted by release and labels LTS, end-of-life, Ubuntu Pro-only and development releases. The data comes from Ubuntu's
meta-releaselists (the same onesdo-release-upgradeuses), and the menu falls back to plain codenames if they can't be fetched:The VM notes and summary now say e.g.
Ubuntu 24.04 LTS (Noble).One
virt-customizecall instead of two, and Ubuntu versions are checked in parallel.SSH keys are checked with
ssh-keygen, so a private key can't be saved or injected./etc/machine-idis blanked in the image so clones don't share DHCP leases.Profile values are escaped when saved, and profiles are always
chmod 600, including ones written by older versions.Password input is hidden and confirmed, and a generated password is shown at the end.
VLAN, disk size, bridge, VM ID, template name, tags, CPU, memory and menu choices are validated. In unattended runs, profile values are checked before any work starts.
The script checks it is running as root and no longer needs python3.
Behaviour changes
/tmpto/var/tmp/ubuntu-cloud-template(can be changed withWORK_DIR). Expect one re-download.DISK_STOR_DEFAULTchanged fromlocaltolocal-lvm.<name>-vendor-data.yaml. An existing snippet is never overwritten.ciupgradeoption ("Upgrade packages" in the Cloud-Init tab), so the setting is visible and changeable per VM in the GUI. It's saved in profiles asCI_UPGRADE(1/0). The default is off, the same as before, and older profiles keep that behaviour.runcmd, starting as commented-out examples. It no longer does package upgrades (Proxmox handles that now) orgrowpart(cloud-init already does it on every boot).ssh_pwauth: trueis only switched on when no SSH key was set.cloud-initis now listed inVIRT_PKGS. It's preinstalled in the cloud images, so this is a no-op safeguard.--force-overwrite, ifqm createfails after the old template was destroyed, the old template is still gone. That window is now as short as possible: after the download, the customise step and all validation.Testing
bash -nandshellcheck -S warningpass.qm,pvesm,wget,virt-customizeand/etc/pve. Scenarios checked:FORCE_OVERWRITE$in valuesimport-from,pvesm pathfor snippets and--run-command).