# Create a VM template from the latest Debian release with settings appropriate for the CCCHH Proxmox clusters

## Prerequisites

The script uses the package [`libguestfs-tools`](https://libguestfs.org)' `virt-builder` to download and customize a Debian image, and then add it as a template to Proxmox.

## Building the Template

### Configuration Options

The following settings are available for configuration by setting the respective environment variable.
Verify that the configured settings are suitable for the cluster you want to create the template for.  
If left unset, the respective default value will be used.

| Variable              | Default                                                                                               | Description                                                            |
| --------------------- | ----------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------- |
| `VMID`                | 9023                                                                                                  | ID the template should have in Proxmox                                 |
| `STORAGE`             | `local-zfs`                                                                                           | Pool the disks should be created in                                    |
| `OS`                  | `debian-12`                                                                                           | `virt-builder` name of the OS to install                               |
| `NAME`                | `chaos-${OS}-tmpl-$(date -u +%Y-%m-%d)`                                                               | name of the template                                                   |
| `BRIDGE`              | `vmbr0,tag=208`                                                                                       | name of the bridge to use and any parameters needed, like the VLAN tag |
| `AUTHORIZED_KEYS_URL` | `https://git.hamburg.ccc.de/CCCHH/infrastructure-authorized-keys/raw/branch/trunk/authorized_keys`    | URL to download the authorized_keys file to use from                   |

### User Account, sshd, and `authorized_keys`

`cloud-init` will create a user `chaos`, by default with a locked password, and authorized keys initialized. Password-less `sudo` is configured, so you can run commands as root.

`sshd` has been configured to listen on port 42666 instead of 22.

### Run the Script

```shell
sudo ./build-proxmox-template
```

## Cloning the Template

Please use "Full Clone" when creating a VM based on this template. Using Linked Clone means that the template's disk cannot be recreated since the linked clones need it. This means that the script cannot update the template.

### Disk Size

The installed `cloud-guest-utils` will automatically increase the root filesystem when you increase the size of the root disk. You will need to reboot the VM for the resize to take place. You can increase the size of the disk right after cloning and before starting the VM for the first time.

### Root Password

The root account is disabled. Use the `chaos` account.