-
Notifications
You must be signed in to change notification settings - Fork 1
/
devstack-vm.pkr.hcl
442 lines (375 loc) · 10.6 KB
/
devstack-vm.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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
packer {
required_version = ">= 1.7.0, < 2.0.0"
required_plugins {
qemu = {
source = "github.com/hashicorp/qemu"
version = ">= 1.0.0, < 2.0.0"
}
}
}
variable "boot_wait" {
type = string
default = "3s"
}
variable "bundle_iso" {
type = string
default = "false"
}
variable "communicator" {
type = string
default = "ssh"
}
variable "country" {
type = string
default = "US"
}
variable "cpus" {
type = string
default = "4"
}
variable "description" {
type = string
default = "Open edX devstack (x86_64 Debian Bullseye 11.x)"
}
variable "disk_size" {
type = string
default = "50000"
}
variable "domain" {
type = string
default = ""
}
variable "guest_os_type" {
type = string
default = "Debian_64"
}
variable "headless" {
type = string
default = "false"
}
variable "host_port_max" {
type = string
default = "4444"
}
variable "host_port_min" {
type = string
default = "2222"
}
variable "http_port_max" {
type = string
default = "9000"
}
variable "http_port_min" {
type = string
default = "8000"
}
variable "iso_checksum" {
type = string
default = "sha512:4460ef6470f6d8ae193c268e213d33a6a5a0da90c2d30c1024784faa4e4473f0c9b546a41e2d34c43fbbd43542ae4fb93cfd5cb6ac9b88a476f1a6877c478674"
# default = "file:http://cdimage.debian.org/cdimage/release/current/amd64/iso-cd/SHA512SUMS"
}
variable "iso_file" {
type = string
default = "debian-11.7.0-amd64-netinst.iso"
}
variable "iso_path_external" {
type = string
default = "https://cdimage.debian.org/cdimage/archive/11.7.0/amd64/iso-cd"
}
variable "keep_registered" {
type = string
default = "false"
}
variable "keyboard" {
type = string
default = "us"
}
variable "language" {
type = string
default = "en"
}
variable "locale" {
type = string
default = "en_US.UTF-8"
}
variable "memory" {
type = string
default = "8096"
}
variable "min_vagrant_version" {
type = string
default = "2.3.0"
}
variable "mirror" {
type = string
default = "ftp.us.debian.org"
}
variable "packer_cache_dir" {
type = string
default = "${env("PACKER_CACHE_DIR")}"
}
variable "preseed_file" {
type = string
default = "base.preseed"
}
variable "qemu_binary" {
type = string
default = "qemu-system-x86_64"
}
variable "shutdown_timeout" {
type = string
default = "5m"
}
variable "skip_export" {
type = string
default = "false"
}
variable "ssh_agent_auth" {
type = string
default = "false"
}
variable "ssh_clear_authorized_keys" {
type = string
default = "false"
}
variable "ssh_disable_agent_forwarding" {
type = string
default = "false"
}
variable "ssh_file_transfer_method" {
type = string
default = "scp"
}
variable "ssh_fullname" {
type = string
default = "Devstack User"
}
variable "ssh_handshake_attempts" {
type = string
default = "10"
}
variable "ssh_keep_alive_interval" {
type = string
default = "5s"
}
variable "ssh_password" {
type = string
default = "devstack"
}
variable "ssh_port" {
type = string
default = "22"
}
variable "ssh_pty" {
type = string
default = "false"
}
variable "ssh_timeout" {
type = string
default = "120m"
}
variable "ssh_username" {
type = string
default = "devstack"
}
variable "start_retry_timeout" {
type = string
default = "5m"
}
variable "system_clock_in_utc" {
type = string
default = "true"
}
variable "timezone" {
type = string
default = "UTC"
}
variable "vagrantfile_template" {
type = string
default = "vagrant.rb.j2"
}
variable "version" {
type = string
default = "0.0.0"
}
variable "vm_name" {
type = string
default = "devstack-bullseye"
}
variable "vnc_vrdp_bind_address" {
type = string
default = "127.0.0.1"
}
variable "vnc_vrdp_port_max" {
type = string
default = "6000"
}
variable "vnc_vrdp_port_min" {
type = string
default = "5900"
}
variable "accelerator" {
type = string
default = "kvm"
}
locals {
output_directory = "build"
}
source "qemu" "devstack-qemu" {
accelerator = var.accelerator
boot_command = [
"<wait><wait><wait><esc><wait><wait><wait>",
"/install.amd/vmlinuz ",
"initrd=/install.amd/initrd.gz ",
"auto=true ",
"url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/${var.preseed_file} ",
"hostname=${var.vm_name} ",
"domain=${var.domain} ",
"interface=auto ",
"vga=788 noprompt quiet --<enter>"
]
boot_wait = var.boot_wait
communicator = var.communicator
cpus = var.cpus
disk_cache = "writeback"
disk_compression = false
disk_discard = "ignore"
disk_image = false
disk_interface = "virtio-scsi"
disk_size = var.disk_size
format = "qcow2"
headless = var.headless
host_port_max = var.host_port_max
host_port_min = var.host_port_min
http_content = { "/${var.preseed_file}" = templatefile(var.preseed_file, { var = var }) }
http_port_max = var.http_port_max
http_port_min = var.http_port_min
iso_checksum = var.iso_checksum
iso_skip_cache = false
iso_target_extension = "iso"
iso_target_path = "${regex_replace(var.packer_cache_dir, "^$", "/tmp")}/${var.iso_file}"
iso_urls = [
"${var.iso_path_external}/${var.iso_file}"
]
machine_type = "pc"
memory = var.memory
net_device = "virtio-net"
output_directory = local.output_directory
qemu_binary = var.qemu_binary
shutdown_command = "echo '${var.ssh_password}' | sudo -E -S poweroff"
shutdown_timeout = var.shutdown_timeout
skip_compaction = true
skip_nat_mapping = false
ssh_agent_auth = var.ssh_agent_auth
ssh_clear_authorized_keys = var.ssh_clear_authorized_keys
ssh_disable_agent_forwarding = var.ssh_disable_agent_forwarding
ssh_file_transfer_method = var.ssh_file_transfer_method
ssh_handshake_attempts = var.ssh_handshake_attempts
ssh_keep_alive_interval = var.ssh_keep_alive_interval
ssh_password = var.ssh_password
ssh_port = var.ssh_port
ssh_pty = var.ssh_pty
ssh_timeout = var.ssh_timeout
ssh_username = var.ssh_username
use_default_display = false
vm_name = "${var.vm_name}.qcow2"
vnc_bind_address = var.vnc_vrdp_bind_address
vnc_port_max = var.vnc_vrdp_port_max
vnc_port_min = var.vnc_vrdp_port_min
}
build {
description = "Can't use variables here yet!"
sources = ["source.qemu.devstack-qemu"]
provisioner "shell" {
binary = false
execute_command = "echo '${var.ssh_password}' | {{ .Vars }} sudo -E -S '{{ .Path }}'"
expect_disconnect = true
inline = ["echo '${var.ssh_username} ALL=(ALL) NOPASSWD: ALL' > /etc/sudoers.d/99${var.ssh_username}", "chmod 0440 /etc/sudoers.d/99${var.ssh_username}"]
inline_shebang = "/bin/sh -e"
skip_clean = false
start_retry_timeout = var.start_retry_timeout
}
provisioner "shell" {
binary = false
execute_command = "echo '${var.ssh_password}' | {{ .Vars }} sudo -E -S '{{ .Path }}'"
expect_disconnect = true
inline = ["apt-get update", "apt-get --yes dist-upgrade", "apt-get clean"]
inline_shebang = "/bin/sh -e"
skip_clean = false
start_retry_timeout = var.start_retry_timeout
}
provisioner "shell" {
binary = false
execute_command = "echo '${var.ssh_password}' | {{ .Vars }} sudo -E -S '{{ .Path }}'"
expect_disconnect = true
inline = ["apt-get --yes install make python docker-compose git python3-pip"]
inline_shebang = "/bin/sh -e"
skip_clean = false
start_retry_timeout = var.start_retry_timeout
}
provisioner "shell" {
binary = false
execute_command = "echo '${var.ssh_password}' | {{ .Vars }} sudo -E -S '{{ .Path }}'"
expect_disconnect = true
inline = ["usermod -aG docker devstack"]
inline_shebang = "/bin/sh -e"
skip_clean = false
start_retry_timeout = var.start_retry_timeout
}
provisioner "shell" {
binary = false
expect_disconnect = true
inline = ["groups $USER"]
inline_shebang = "/bin/sh -e"
skip_clean = false
start_retry_timeout = var.start_retry_timeout
}
provisioner "shell" {
binary = false
execute_command = "echo '${var.ssh_password}' | {{ .Vars }} sudo -E -S '{{ .Path }}'"
expect_disconnect = true
inline = ["systemctl status docker"]
inline_shebang = "/bin/sh -e"
skip_clean = false
start_retry_timeout = var.start_retry_timeout
}
provisioner "shell" {
binary = false
execute_command = "echo '${var.ssh_password}' | {{ .Vars }} sudo -E -S '{{ .Path }}'"
expect_disconnect = true
inline = ["sed -i 's/GRUB_CMDLINE_LINUX=\"\"/GRUB_CMDLINE_LINUX=\"net.ifnames=0 biosdevname=0 interface=auto\"/' /etc/default/grub", "update-grub"]
inline_shebang = "/bin/sh -e"
skip_clean = false
start_retry_timeout = var.start_retry_timeout
}
provisioner "shell" {
binary = false
execute_command = "echo '${var.ssh_password}' | {{ .Vars }} sudo -E -S '{{ .Path }}'"
expect_disconnect = true
inline = ["echo 'allow-hotplug eth0' >> /etc/network/interfaces", "echo 'iface eth0 inet dhcp' >> /etc/network/interfaces"]
inline_shebang = "/bin/sh -e"
skip_clean = false
start_retry_timeout = var.start_retry_timeout
}
provisioner "shell" {
binary = false
execute_command = "echo '${var.ssh_password}' | {{ .Vars }} sudo -E -S '{{ .Path }}'"
expect_disconnect = true
inline = ["reboot"]
inline_shebang = "/bin/sh -e"
skip_clean = false
start_retry_timeout = var.start_retry_timeout
}
provisioner "shell" {
pause_before = "60s"
binary = false
expect_disconnect = true
script = "mkdir-clone-and-provision.sh"
skip_clean = false
start_retry_timeout = var.start_retry_timeout
}
post-processor "checksum" {
checksum_types = ["md5", "sha1", "sha256", "sha512"]
output = "${local.output_directory}/${var.vm_name}_{{.ChecksumType}}.checksum"
}
}