forked from goffinet/packer-kvm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jammy.pkr.hcl
114 lines (96 loc) · 3.7 KB
/
jammy.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
variable "config_file" {
type = string
default = "jammy"
}
variable "cpu" {
type = string
default = "2"
}
variable "destination_server" {
type = string
default = "download.goffinet.org"
}
variable "disk_size" {
type = string
default = "40000"
}
variable "headless" {
type = string
default = "true"
}
variable "iso_checksum" {
type = string
default = "sha256:10f19c5b2b8d6db711582e0e27f5116296c34fe4b313ba45f9b201a5007056cb"
}
variable "iso_url" {
type = string
default = "http://releases.ubuntu.com/22.04/ubuntu-22.04.1-live-server-amd64.iso"
}
variable "name" {
type = string
default = "jammy"
}
variable "ram" {
type = string
default = "2048"
}
variable "ssh_password" {
type = string
default = "ubuntu"
}
variable "ssh_username" {
type = string
default = "ubuntu"
}
variable "version" {
type = string
default = ""
}
source "qemu" "jammy" {
accelerator = "kvm"
boot_command = ["<esc><esc><esc><esc>e<wait>", "<del><del><del><del><del><del><del><del>", "<del><del><del><del><del><del><del><del>", "<del><del><del><del><del><del><del><del>", "<del><del><del><del><del><del><del><del>", "<del><del><del><del><del><del><del><del>", "<del><del><del><del><del><del><del><del>", "<del><del><del><del><del><del><del><del>", "<del><del><del><del><del><del><del><del>", "<del><del><del><del><del><del><del><del>", "<del><del><del><del><del><del><del><del>", "<del><del><del><del><del><del><del><del>", "<del><del><del><del><del><del><del><del>", "<del><del><del><del><del><del><del><del>", "<del><del><del><del><del><del><del><del>", "linux /casper/vmlinuz --- autoinstall ds=\"nocloud-net;seedfrom=http://{{ .HTTPIP }}:{{ .HTTPPort }}/http/${var.config_file}/\"<enter><wait>", "initrd /casper/initrd<enter><wait>", "boot<enter>", "<enter><f10><wait>"]
boot_wait = "3s"
disk_cache = "none"
disk_compression = true
disk_discard = "ignore"
disk_interface = "virtio"
disk_size = var.disk_size
format = "qcow2"
headless = var.headless
host_port_max = 2229
host_port_min = 2222
http_directory = "."
http_port_max = 10089
http_port_min = 10082
iso_checksum = var.iso_checksum
iso_url = var.iso_url
net_device = "virtio-net"
output_directory = "artifacts/qemu/${var.name}${var.version}"
qemu_binary = "/usr/bin/qemu-system-x86_64"
qemuargs = [["-m", "${var.ram}M"], ["-smp", "${var.cpu}"]]
shutdown_command = "echo '${var.ssh_password}' | sudo -S shutdown -P now"
ssh_handshake_attempts = 500
ssh_password = var.ssh_password
ssh_timeout = "45m"
ssh_username = var.ssh_username
ssh_wait_timeout = "45m"
}
build {
sources = ["source.qemu.jammy"]
provisioner "shell" {
execute_command = "{{ .Vars }} sudo -E bash '{{ .Path }}'"
inline = ["sudo apt-get update", "sudo apt-get -y install software-properties-common", "sudo apt-add-repository --yes --update ppa:ansible/ansible", "sudo apt update", "sudo apt -y install ansible"]
}
provisioner "ansible-local" {
playbook_dir = "ansible"
playbook_file = "ansible/playbook.yml"
}
provisioner "shell" {
execute_command = "{{ .Vars }} sudo -E bash '{{ .Path }}'"
inline = ["sudo apt -y remove ansible", "sudo apt-get clean", "sudo apt-get -y autoremove --purge"]
}
post-processor "shell-local" {
environment_vars = ["IMAGE_NAME=${var.name}", "IMAGE_VERSION=${var.version}", "DESTINATION_SERVER=${var.destination_server}"]
script = "scripts/push-image.sh"
}
}