-
Notifications
You must be signed in to change notification settings - Fork 0
/
packer.pkr.hcl
111 lines (105 loc) · 3.82 KB
/
packer.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
packer {
required_plugins {
qemu = {
version = ">= 1.0.1"
source = "github.com/hashicorp/qemu"
}
}
}
source "qemu" "debian" {
accelerator = "kvm"
boot_command = [
"<wait><wait><wait><esc><wait><wait><wait>",
"/install.amd/vmlinuz ",
"initrd=/install.amd/initrd.gz ",
"auto=true ",
"url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/ks ",
"hostname=${var.vm_name} ",
"domain=${var.domain} ",
"interface=auto ",
"vga=788 noprompt quiet --<enter>"
]
boot_wait = "3s"
communicator = "ssh"
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 = true
http_content = {
"/ks" = templatefile("${path.root}/preseeds/${var.preseed_file}",
{
hostname = "${var.vm_name}",
ssh_fullname = "${var.ssh_fullname}",
ssh_username = "${var.ssh_username}",
ssh_password = "${var.ssh_password}",
})
}
iso_checksum = var.iso_checksum
iso_skip_cache = false
iso_target_extension = "iso"
iso_urls = ["${var.iso_path}/${var.iso_file}"]
machine_type = "pc"
memory = var.memory
net_device = "virtio-net"
qemu_binary = var.qemu_binary
shutdown_command = "sudo shutdown 0"
shutdown_timeout = var.shutdown_timeout
skip_compaction = true
skip_nat_mapping = false
ssh_clear_authorized_keys = var.ssh_clear_authorized_keys
ssh_password = var.ssh_password
ssh_timeout = var.ssh_timeout
ssh_username = var.ssh_username
use_default_display = false
vm_name = var.vm_name
vnc_bind_address = var.vnc_vrdp_bind_address
output_directory = "build"
}
build {
sources = [
"source.qemu.debian"
]
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 install cloud-init --yes",
"rm -Rf /etc/network/interfaces.d/50-cloud-init",
"cloud-init init --local",
"echo \"source /etc/network/interfaces.d/*\" > /etc/network/interfaces",
"apt-get clean",
"rm -Rf /var/lib/cloud",
]
inline_shebang = "/bin/sh -e"
skip_clean = false
start_retry_timeout = var.start_retry_timeout
}
}