Blame

2e4a09 MB Tech 2025-05-25 18:42:24 1
# Create Template
2
3
## Create a template using Ubuntu Cloud Image and customization script
66602a mvbingham 2025-05-25 14:55:09 4
04195a MB Tech 2025-05-25 19:00:26 5
### Customization script (`ubuntu.yml`)
66602a mvbingham 2025-05-25 14:55:09 6
7
Once the snippets has been added to the local location you can cd to the /var/lib/snippets directory
8
262ab3 MB Tech 2025-05-25 18:56:12 9
```
66602a mvbingham 2025-05-25 14:55:09 10
cd /var/lib/vz/snippets/
11
```
12
Next using nano create the ubuntu.yaml file
13
262ab3 MB Tech 2025-05-25 18:56:12 14
```
66602a mvbingham 2025-05-25 14:55:09 15
nano ubuntu.yaml
16
```
17
18
copy and paste the following code
19
20
```yaml
21
#cloud-config
22
runcmd:
23
- apt update
24
- apt install -y qemu-guest-agent
25
- systemctl enable ssh
26
- apt install -y apt-transport-https ca-certificates curl software-properties-common
27
- curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
28
- echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu noble stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null
29
- apt update
30
- apt-cache policy docker-ce
31
- apt install -y docker-ce
32
- systemctl status docker
33
- usermod -aG docker mbtech
622ee2 MB Tech 2025-05-25 19:41:40 34
- echo "<username> ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
66602a mvbingham 2025-05-25 14:55:09 35
- mkdir -p ~/.docker/cli-plugins/
36
- curl -SL https://github.com/docker/compose/releases/download/v2.36.0/docker-compose-linux-x86_64 -o ~/.docker/cli-plugins/docker-compose
37
- chmod +x ~/.docker/cli-plugins/docker-compose
38
# Taken from https://forum.proxmox.com/threads/combining-custom-cloud-init-with-auto-generated.59008/page-3#post-428772
39
```
622ee2 MB Tech 2025-05-25 19:41:40 40
::: info
41
# Reminder you need to change the user name for sudoers file:
b46b1f MB Tech 2025-05-25 19:42:30 42
```
622ee2 MB Tech 2025-05-25 19:41:40 43
echo "<username> ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
b46b1f MB Tech 2025-05-25 19:42:30 44
```
622ee2 MB Tech 2025-05-25 19:41:40 45
:::
46
47
66602a mvbingham 2025-05-25 14:55:09 48
Next need to create the bash script to create the template
49
04195a MB Tech 2025-05-25 19:00:26 50
```
51
cd ~
52
```
262ab3 MB Tech 2025-05-25 18:56:12 53
```
66602a mvbingham 2025-05-25 14:55:09 54
nano create-template.sh
55
```
56
57
```bash
58
#! /bin/bash
59
60
VMID=<Your ID you would Like to use>
61
STORAGE=<Your storage location>
62
USER=<your username>
63
set -x
64
rm -f noble-server-cloudimg-amd64.img
65
wget -q https://cloud-images.ubuntu.com/noble/current/noble-server-cloudimg-amd64.img
66
qemu-img resize noble-server-cloudimg-amd64.img 8G
67
qm destroy $VMID
68
qm create $VMID --name "ubuntu-noble-template-5" --ostype l26 \
69
--memory 1024 --balloon 0 \
70
--agent 1 \
71
--bios ovmf --machine q35 --efidisk0 $STORAGE:0,pre-enrolled-keys=0 \
72
--cpu host --socket 1 --cores 1 \
73
--vga serial0 --serial0 socket \
74
--net0 virtio,bridge=vmbr0
75
qm importdisk $VMID noble-server-cloudimg-amd64.img $STORAGE
76
qm set $VMID --scsihw virtio-scsi-pci --virtio0 $STORAGE:$VMID/vm-$VMID-disk-1.raw,discard=on
77
qm set $VMID --boot order=virtio0
78
qm set $VMID --scsi1 $STORAGE:cloudinit
79
80
cat << EOF | tee /var/lib/vz/snippets/ubuntu.yaml
81
#cloud-config
82
runcmd:
83
- apt update
84
- apt install -y qemu-guest-agent
85
- systemctl enable ssh
86
- apt install -y apt-transport-https ca-certificates curl software-properties-common
87
- curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
88
- echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu noble stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null
89
- apt update
90
- apt-cache policy docker-ce
91
- apt install -y docker-ce
92
- systemctl status docker
93
- usermod -aG docker mbtech
94
- echo "mbtech ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
95
- mkdir -p ~/.docker/cli-plugins/
96
- curl -SL https://github.com/docker/compose/releases/download/v2.36.0/docker-compose-linux-x86_64 -o ~/.docker/cli-plugins/docker-compose
97
- chmod +x ~/.docker/cli-plugins/docker-compose
98
# Taken from https://forum.proxmox.com/threads/combining-custom-cloud-init-with-auto-generated.59008/page-3#post-428772
99
EOF
100
101
qm set $VMID --cicustom "vendor=local:snippets/ubuntu.yaml"
102
qm set $VMID --tags ubuntu-template,noble,cloudinit
103
qm set $VMID --ciuser $USER
104
qm set $VMID --sshkeys ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIL7OapWuqeqK4mOF8LEJsBunfNUKJSpXmWkqACGCcQ4y mbtech@ubuntusemaphore
105
qm set $VMID --ipconfig0 ip=dhcp
106
qm template $VMID
107
```
04195a MB Tech 2025-05-25 19:00:26 108
::: info
109
# Reminder you need to change the variables:
f4f06e MB Tech 2025-05-25 19:01:12 110
```
04195a MB Tech 2025-05-25 19:00:26 111
VMID=<Your ID you would Like to use>
112
STORAGE=<Your storage location>
113
USER=<your username>
f4f06e MB Tech 2025-05-25 19:01:12 114
```
04195a MB Tech 2025-05-25 19:00:26 115
:::
66602a mvbingham 2025-05-25 14:55:09 116
ff3441 MB Tech 2025-05-25 20:11:49 117
Make sure that the bash script is executable
118
```
119
chmod 755 create-template.sh
120
```
e0b20f MB Tech 2025-05-25 20:12:34 121
```
122
./create-template.sh
123
```
ff3441 MB Tech 2025-05-25 20:11:49 124
66602a mvbingham 2025-05-25 14:55:09 125
## Youtube Video
10b697 MB Tech 2025-05-25 19:01:56 126
9b72f3 MB Tech 2025-05-25 20:22:59 127
<iframe width="560" height="315" src="https://www.youtube.com/embed/DU195xLjQdA?si=3_uwn7UTtyqxTX2V" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>