-
Notifications
You must be signed in to change notification settings - Fork 4
/
config.pkr.hcl
137 lines (127 loc) · 3.55 KB
/
config.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
packer {
required_plugins {
ansible = {
version = ">= 1.1.0"
source = "github.com/hashicorp/ansible"
}
qemu = {
version = ">= 1.0.9"
source = "github.com/hashicorp/qemu"
}
}
}
data "http" "example" {
url = "https://mir.archlinux.fr/iso/latest/sha256sums.txt"
}
locals {
firmware = "/usr/share/edk2-ovmf/x64/OVMF.fd"
iso_url = "https://mir.archlinux.fr/iso/latest/archlinux-x86_64.iso"
iso_checksum = "${split(" ", split("\n", data.http.example.body)[1])[0] }"
headless = true
crypt_passphrase = "password"
ssh_root_username = "root"
ssh_root_password = "root"
unix_username = "username"
unix_password = "password"
vm_name = "archlinux-workstation"
cpus = "4"
memory = "8192"
disk_size = "20000"
keymap = "us"
}
source "qemu" "kvm-init" {
vm_name = "${local.vm_name}"
headless = "${local.headless}"
cpus = "${local.cpus}"
memory = "${local.memory}"
disk_size = "${local.disk_size}"
firmware = "${local.firmware}"
iso_url = "${local.iso_url}"
iso_checksum = "${local.iso_checksum}"
ssh_password = "${local.ssh_root_password}"
ssh_username = "${local.ssh_root_username}"
ssh_wait_timeout = "60m"
boot_wait = "3s"
boot_command = [
"<enter><wait60>",
"echo ${local.ssh_root_username}:${local.ssh_root_password} | chpasswd<enter>"
]
shutdown_command = "shutdown -P now"
output_directory = "dist/base"
}
source "qemu" "kvm-setup" {
vm_name = "${local.vm_name}"
qemuargs = [
local.keymap != "us" ? [ "-k", "${local.keymap}" ] : [ "-k", "en-us" ]
]
headless = "${local.headless}"
cpus = "${local.cpus}"
memory = "${local.memory}"
disk_size = "${local.disk_size}"
disk_image = true
firmware = "${local.firmware}"
iso_url = "dist/base/archlinux-workstation"
iso_checksum = "none"
ssh_password = "${local.unix_password}"
ssh_username = "${local.unix_username}"
ssh_wait_timeout = "60m"
boot_wait = "3s"
boot_command = [
"<wait10>",
"${local.crypt_passphrase}<enter>"
]
shutdown_command = "sudo shutdown -P now"
output_directory = "dist/final"
}
build {
sources = ["source.qemu.kvm-init"]
provisioner "ansible" {
playbook_file = "init.yml"
inventory_file = "inventories/packer"
ansible_env_vars = [
"ANSIBLE_FORCE_COLOR=1",
"ANSIBLE_DISPLAY_OK_HOSTS=1",
"ANSIBLE_DISPLAY_SKIPPED_HOSTS=1"
]
extra_arguments = [
// "-vvv",
"-D",
"-e ansible_host=localhost",
"-e ansible_port=${build.Port}",
"-e ansible_user=${local.ssh_root_username}",
"-e ansible_ssh_pass=${local.ssh_root_password}",
"-e crypt_passphrase=${local.crypt_passphrase}",
"-e unix_username=${local.unix_username}",
"-e unix_password=${local.unix_password}",
"-e keymap=${local.keymap}"
]
}
provisioner "shell-local" {
inline = ["echo '==> Test this image with: ./kvm-run.sh'"]
}
}
build {
sources = ["source.qemu.kvm-setup"]
provisioner "ansible" {
playbook_file = "setup.yml"
inventory_file = "inventories/packer"
ansible_env_vars = [
"ANSIBLE_FORCE_COLOR=1",
"ANSIBLE_DISPLAY_OK_HOSTS=1",
"ANSIBLE_DISPLAY_SKIPPED_HOSTS=1"
]
extra_arguments = [
// "-vvv",
"-D",
"-e ansible_host=localhost",
"-e ansible_port=${build.Port}",
"-e ansible_user=${local.unix_username}",
"-e ansible_ssh_pass=${local.unix_password}",
"-e unix_username=${local.unix_username}",
"-e keymap=${local.keymap}"
]
}
provisioner "shell-local" {
inline = ["echo '==> Test this image with: ./kvm-run.sh final'"]
}
}