forked from rgl/ubuntu-vagrant
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathubuntu.pkr.hcl
286 lines (264 loc) · 6.64 KB
/
ubuntu.pkr.hcl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
packer {
required_plugins {
# see https://github.com/hashicorp/packer-plugin-qemu
qemu = {
version = ">= 1.1.0"
source = "github.com/hashicorp/qemu"
}
# see https://github.com/hashicorp/packer-plugin-hyperv
hyperv = {
version = ">= 1.1.3"
source = "github.com/hashicorp/hyperv"
}
# see https://github.com/hashicorp/packer-plugin-vagrant
vagrant = {
version = ">= 1.1.4"
source = "github.com/hashicorp/vagrant"
}
}
}
variable "version" {
type = string
}
variable "disk_size" {
type = string
default = 8 * 1024
}
variable "iso_url" {
type = string
default = "https://releases.ubuntu.com/24.04/ubuntu-24.04-live-server-amd64.iso"
}
variable "iso_checksum" {
type = string
default = "sha256:8762f7e74e4d64d72fceb5f70682e6b069932deedb4949c6975d0f0fe0a91be3"
}
variable "proxmox_node" {
type = string
default = env("PROXMOX_NODE")
}
variable "hyperv_switch_name" {
type = string
default = env("HYPERV_SWITCH_NAME")
}
variable "hyperv_vlan_id" {
type = string
default = env("HYPERV_VLAN_ID")
}
variable "vagrant_box" {
type = string
}
locals {
boot_command = [
"c<wait>",
"linux /casper/vmlinuz",
" net.ifnames=0",
" autoinstall",
"<enter><wait5s>",
"initrd /casper/initrd",
"<enter><wait5s>",
"boot",
"<enter><wait5s>",
]
}
source "hyperv-iso" "ubuntu-amd64" {
cd_label = "cidata"
cd_files = [
"tmp/hyperv-autoinstall-cloud-init-data/user-data",
"autoinstall-cloud-init-data/meta-data",
]
boot_command = local.boot_command
boot_wait = "5s"
boot_order = ["SCSI:0:0"]
first_boot_device = "DVD"
cpus = 2
memory = 2048
disk_size = var.disk_size
generation = 2
headless = true
iso_checksum = var.iso_checksum
iso_url = var.iso_url
switch_name = var.hyperv_switch_name
temp_path = "tmp"
vlan_id = var.hyperv_vlan_id
ssh_username = "vagrant"
ssh_password = "vagrant"
ssh_timeout = "60m"
shutdown_command = "sudo -S poweroff"
}
source "qemu" "ubuntu-amd64" {
accelerator = "kvm"
cd_label = "cidata"
cd_files = [
"autoinstall-cloud-init-data/user-data",
"autoinstall-cloud-init-data/meta-data",
]
machine_type = "q35"
boot_command = local.boot_command
boot_wait = "5s"
disk_cache = "unsafe"
disk_discard = "unmap"
disk_interface = "virtio-scsi"
disk_size = var.disk_size
format = "qcow2"
headless = true
net_device = "virtio-net"
iso_checksum = var.iso_checksum
iso_url = var.iso_url
cpus = 2
memory = 2048
qemuargs = [
["-cpu", "host"],
]
ssh_username = "vagrant"
ssh_password = "vagrant"
ssh_timeout = "60m"
shutdown_command = "sudo -S poweroff"
}
source "qemu" "ubuntu-uefi-amd64" {
accelerator = "kvm"
cd_label = "cidata"
cd_files = [
"tmp/libvirt-uefi-autoinstall-cloud-init-data/user-data",
"autoinstall-cloud-init-data/meta-data",
]
machine_type = "q35"
boot_command = local.boot_command
boot_wait = "5s"
disk_discard = "unmap"
disk_interface = "virtio-scsi"
disk_size = var.disk_size
format = "qcow2"
headless = true
net_device = "virtio-net"
iso_checksum = var.iso_checksum
iso_url = var.iso_url
cpus = 2
memory = 2048
qemuargs = [
["-cpu", "host"],
["-bios", "/usr/share/ovmf/OVMF.fd"],
["-device", "virtio-vga"],
["-device", "virtio-scsi-pci,id=scsi0"],
["-device", "scsi-hd,bus=scsi0.0,drive=drive0"],
]
ssh_username = "vagrant"
ssh_password = "vagrant"
ssh_timeout = "60m"
shutdown_command = "sudo -S poweroff"
}
source "proxmox-iso" "ubuntu-amd64" {
template_name = "template-ubuntu-${var.version}"
template_description = "See https://github.com/rgl/ubuntu-vagrant"
tags = "ubuntu-${var.version};template"
insecure_skip_tls_verify = true
node = var.proxmox_node
machine = "q35"
boot_command = local.boot_command
boot_wait = "5s"
bios = "ovmf"
efi_config {
efi_storage_pool = "local-lvm"
}
cpu_type = "host"
cores = 2
memory = 2 * 1024
vga {
type = "qxl"
memory = 16
}
network_adapters {
model = "virtio"
bridge = "vmbr0"
}
scsi_controller = "virtio-scsi-single"
disks {
type = "scsi"
io_thread = true
ssd = true
discard = true
disk_size = "${var.disk_size}M"
storage_pool = "local-lvm"
}
iso_storage_pool = "local"
iso_url = var.iso_url
iso_checksum = var.iso_checksum
unmount_iso = true
additional_iso_files {
iso_storage_pool = "local"
cd_label = "cidata"
cd_files = [
"tmp/proxmox-autoinstall-cloud-init-data/user-data",
"autoinstall-cloud-init-data/meta-data",
]
unmount = true
}
os = "l26"
ssh_username = "vagrant"
ssh_password = "vagrant"
ssh_timeout = "60m"
}
build {
sources = [
"source.hyperv-iso.ubuntu-amd64",
"source.qemu.ubuntu-amd64",
"source.qemu.ubuntu-uefi-amd64",
"source.proxmox-iso.ubuntu-amd64",
]
provisioner "shell" {
execute_command = "echo vagrant | sudo -S {{ .Vars }} bash {{ .Path }}"
scripts = [
"upgrade.sh",
]
}
provisioner "shell" {
execute_command = "sudo -S {{ .Vars }} bash {{ .Path }}"
expect_disconnect = true
scripts = [
"reboot.sh",
]
}
provisioner "shell" {
execute_command = "sudo -S {{ .Vars }} bash {{ .Path }}"
scripts = [
"provision-guest-additions.sh",
]
}
provisioner "shell" {
execute_command = "sudo -S {{ .Vars }} bash {{ .Path }}"
expect_disconnect = true
scripts = [
"reboot.sh",
]
}
provisioner "shell" {
execute_command = "sudo -S {{ .Vars }} bash {{ .Path }}"
scripts = [
"provision.sh",
]
}
provisioner "shell-local" {
environment_vars = [
"PACKER_VERSION=${packer.version}",
"PACKER_VM_NAME=${build.ID}",
]
only = [
"hyperv-iso.ubuntu-amd64",
]
scripts = ["provision-local-hyperv.cmd"]
}
post-processor "vagrant" {
only = [
"qemu.ubuntu-amd64",
"hyperv-iso.ubuntu-amd64",
]
output = var.vagrant_box
vagrantfile_template = "Vagrantfile.template"
}
post-processor "vagrant" {
only = [
"qemu.ubuntu-uefi-amd64",
]
output = var.vagrant_box
vagrantfile_template = "Vagrantfile-uefi.template"
}
}