-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathubuntu_jammy.pkr.hcl
93 lines (81 loc) · 2.1 KB
/
ubuntu_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
packer {
required_version = ">= 1.8.0"
required_plugins {
qemu = {
version = "= 1.0.7"
source = "github.com/hashicorp/qemu"
}
ansible = {
version = "= 1.0.3"
source = "github.com/hashicorp/ansible"
}
}
}
variable "arch" {
type = string
}
variable "firmware" {
type = string
}
variable "qemu_binary" {
type = string
}
variable "machine_type" {
type = string
}
variable "cpu_type" {
type = string
}
variable "kubernetes_version" {
type = string
}
variable "sudo_password" {
type = string
sensitive = true
}
source "qemu" "ubuntu_jammy" {
iso_url = "https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-${var.arch}.img"
iso_checksum = "file:https://cloud-images.ubuntu.com/jammy/current/SHA256SUMS"
disk_image = true
disk_size = "8G"
format = "qcow2"
disk_interface = "virtio"
firmware = var.firmware
use_pflash = true
qemu_binary = var.qemu_binary
machine_type = var.machine_type
qemuargs = [
["-cpu", "${var.cpu_type}"],
["-device", "virtio-rng-pci,rng=rng0"],
["-object", "rng-random,filename=/dev/urandom,id=rng0"]
]
headless = true
memory = 1024
net_device = "virtio-net"
output_directory = "ubuntu_jammy"
vm_name = "disk.img"
cd_content = {
"meta-data" = ""
"user-data" = "#cloud-config\npassword: ${var.sudo_password}\nchpasswd: { expire: False }\nssh_pwauth: True"
}
cd_label = "cidata"
shutdown_command = "echo 'packer' | sudo -S shutdown -P now"
ssh_username = "ubuntu"
ssh_password = var.sudo_password
ssh_timeout = "30m"
disable_vnc = true
}
build {
sources = ["source.qemu.ubuntu_jammy"]
provisioner "shell" {
inline = ["sudo cloud-init clean --logs"]
}
provisioner "ansible" {
user = "ubuntu"
playbook_file = "./playbook.yml"
extra_arguments = ["--extra-vars", "KUBERNETES_VERSION=${var.kubernetes_version}"]
ansible_env_vars = [
"ANSIBLE_SSH_ARGS='-o PubkeyAcceptedKeyTypes=+ssh-rsa -o HostkeyAlgorithms=+ssh-rsa'"
]
}
}