Pretty straight forward start on this one we will build a Debian VM with minimal resources like 1 CPU and 1GB of RAM. Power on the VM and preferably SSH on to it.

We’ll start by inatlling the cloud-init package on the VM:

apt install cloud-init

Next we remove the host SSH keys, as they will be regenerated every time a VM is spun up from the template:

rm -rf /etc/ssh/ssh_host_*

Now remove machine-id:

truncate -s 0 /etc/machine-id

Check /var/lib/dbus/machine-id is a symbolic link to /etc/machine-id:

ls -la /var/lib/dbus/machine-id

If the file is not present, create the link:

ls -s /etc/machine-d /var/lib/dbus/machine-id

Clean the package manager:

apt clean

Power off the the VM:

poweroff

Once the VM is turned off, create the template:

From the left-hand side menu locate the VM in the cluster/instance, select it and convert to template. This process is considerate “destructive” as it cannot be reversed, please ensure to select the correct VM.

With the VM converted to template we need a small tweaks to complete the process:

  1. Remove the ISO image: select the template in the “Datacenter” view –> Hardware –> edit CD/DVD drive –> Select “Do not use any media”
  2. Add cloudinit drive to the VM –> Add the drive to the local storage
  3. Select “Cloud-init” from the template’s menu and set username, password, DNS domain, DNS server, SSH public keys, Upgrade packages set to “Yes” – this will automatically update the VM after being cloned.

For the final step above the “Cloud-init” settings select Regenerate Image. And we are done! :)