upgrade to packer hcl templates

This commit is contained in:
Rui Lopes
2023-08-07 08:21:27 +01:00
parent e3161ae41b
commit 9b98ee4fe3
9 changed files with 693 additions and 417 deletions

1
.gitignore vendored
View File

@@ -4,5 +4,6 @@ output-*/
shared/
tmp/
*.box
*.box.json
*.log
secrets*

View File

@@ -1,3 +1,6 @@
SHELL=bash
.SHELLFLAGS=-euo pipefail -c
VAR_FILE :=
VAR_FILE_OPTION := $(addprefix -var-file=,$(VAR_FILE))
@@ -10,52 +13,83 @@ build-virtualbox: proxmox-ve-amd64-virtualbox.box
build-hyperv: proxmox-ve-amd64-hyperv.box
build-vsphere: proxmox-ve-amd64-vsphere.box
proxmox-ve-amd64-libvirt.box: provisioners/*.sh proxmox-ve.json Vagrantfile.template $(VAR_FILE)
proxmox-ve-amd64-libvirt.box: provisioners/*.sh proxmox-ve.pkr.hcl Vagrantfile.template $(VAR_FILE)
rm -f $@
PACKER_OUTPUT_BASE_DIR=$${PACKER_OUTPUT_BASE_DIR:-.} PACKER_KEY_INTERVAL=10ms CHECKPOINT_DISABLE=1 PACKER_LOG=1 PACKER_LOG_PATH=$@.log \
packer build -only=proxmox-ve-amd64-libvirt -on-error=abort -timestamp-ui $(VAR_FILE_OPTION) proxmox-ve.json
@echo Box successfully built!
@echo to add it to vagrant run:
@echo vagrant box add -f proxmox-ve-amd64 $@
CHECKPOINT_DISABLE=1 \
PACKER_LOG=1 \
PACKER_LOG_PATH=$@.init.log \
packer init proxmox-ve.pkr.hcl
PACKER_OUTPUT_BASE_DIR=$${PACKER_OUTPUT_BASE_DIR:-.} \
PACKER_KEY_INTERVAL=10ms \
CHECKPOINT_DISABLE=1 \
PACKER_LOG=1 \
PACKER_LOG_PATH=$@.log \
PKR_VAR_vagrant_box=$@ \
packer build -only=qemu.proxmox-ve-amd64 -on-error=abort -timestamp-ui $(VAR_FILE_OPTION) proxmox-ve.pkr.hcl
@./box-metadata.sh libvirt proxmox-ve-amd64 $@
proxmox-ve-uefi-amd64-libvirt.box: provisioners/*.sh proxmox-ve.json Vagrantfile-uefi.template $(VAR_FILE)
proxmox-ve-uefi-amd64-libvirt.box: provisioners/*.sh proxmox-ve.pkr.hcl Vagrantfile-uefi.template $(VAR_FILE)
rm -f $@
PACKER_OUTPUT_BASE_DIR=$${PACKER_OUTPUT_BASE_DIR:-.} PACKER_KEY_INTERVAL=10ms CHECKPOINT_DISABLE=1 PACKER_LOG=1 PACKER_LOG_PATH=$@.log \
packer build -only=proxmox-ve-uefi-amd64-libvirt -on-error=abort -timestamp-ui $(VAR_FILE_OPTION) proxmox-ve.json
@echo Box successfully built!
@echo to add it to vagrant run:
@echo vagrant box add -f proxmox-ve-uefi-amd64 $@
CHECKPOINT_DISABLE=1 \
PACKER_LOG=1 \
PACKER_LOG_PATH=$@.init.log \
packer init proxmox-ve.pkr.hcl
PACKER_OUTPUT_BASE_DIR=$${PACKER_OUTPUT_BASE_DIR:-.} \
PACKER_KEY_INTERVAL=10ms \
CHECKPOINT_DISABLE=1 \
PACKER_LOG=1 \
PACKER_LOG_PATH=$@.log \
PKR_VAR_vagrant_box=$@ \
packer build -only=qemu.proxmox-ve-uefi-amd64 -on-error=abort -timestamp-ui $(VAR_FILE_OPTION) proxmox-ve.pkr.hcl
@./box-metadata.sh libvirt proxmox-ve-uefi-amd64 $@
proxmox-ve-amd64-virtualbox.box: provisioners/*.sh proxmox-ve.json Vagrantfile.template $(VAR_FILE)
proxmox-ve-amd64-virtualbox.box: provisioners/*.sh proxmox-ve.pkr.hcl Vagrantfile.template $(VAR_FILE)
rm -f $@
PACKER_OUTPUT_BASE_DIR=$${PACKER_OUTPUT_BASE_DIR:-.} CHECKPOINT_DISABLE=1 PACKER_LOG=1 PACKER_LOG_PATH=$@.log \
packer build -only=proxmox-ve-amd64-virtualbox -on-error=abort -timestamp-ui $(VAR_FILE_OPTION) proxmox-ve.json
@echo Box successfully built!
@echo to add it to vagrant run:
@echo vagrant box add -f proxmox-ve-amd64 $@
CHECKPOINT_DISABLE=1 \
PACKER_LOG=1 \
PACKER_LOG_PATH=$@.init.log \
packer init proxmox-ve.pkr.hcl
PACKER_OUTPUT_BASE_DIR=$${PACKER_OUTPUT_BASE_DIR:-.} \
CHECKPOINT_DISABLE=1 \
PACKER_LOG=1 \
PACKER_LOG_PATH=$@.log \
PKR_VAR_vagrant_box=$@ \
packer build -only=virtualbox-iso.proxmox-ve-amd64 -on-error=abort -timestamp-ui $(VAR_FILE_OPTION) proxmox-ve.pkr.hcl
@./box-metadata.sh virtualbox proxmox-ve-amd64 $@
proxmox-ve-amd64-hyperv.box: provisioners/*.sh proxmox-ve.json Vagrantfile.template $(VAR_FILE)
proxmox-ve-amd64-hyperv.box: provisioners/*.sh proxmox-ve.pkr.hcl Vagrantfile.template $(VAR_FILE)
rm -f $@
mkdir -p tmp
PACKER_OUTPUT_BASE_DIR=$${PACKER_OUTPUT_BASE_DIR:-.} CHECKPOINT_DISABLE=1 PACKER_LOG=1 PACKER_LOG_PATH=$@.log \
packer build -only=proxmox-ve-amd64-hyperv -on-error=abort -timestamp-ui $(VAR_FILE_OPTION) proxmox-ve.json
@echo Box successfully built!
@echo to add it to vagrant run:
@echo vagrant box add -f proxmox-ve-amd64 $@
CHECKPOINT_DISABLE=1 \
PACKER_LOG=1 \
PACKER_LOG_PATH=$@.init.log \
packer init proxmox-ve.pkr.hcl
PACKER_OUTPUT_BASE_DIR=$${PACKER_OUTPUT_BASE_DIR:-.} \
CHECKPOINT_DISABLE=1 \
PACKER_LOG=1 \
PACKER_LOG_PATH=$@.log \
PKR_VAR_vagrant_box=$@ \
packer build -only=hyperv-iso.proxmox-ve-amd64 -on-error=abort -timestamp-ui $(VAR_FILE_OPTION) proxmox-ve.pkr.hcl
@./box-metadata.sh hyperv proxmox-ve-amd64 $@
proxmox-ve-amd64-vsphere.box: provisioners/*.sh proxmox-ve-vsphere.json $(VAR_FILE)
proxmox-ve-amd64-vsphere.box: provisioners/*.sh proxmox-ve-vsphere.pkr.hcl $(VAR_FILE)
rm -f $@
mkdir -p tmp
PACKER_OUTPUT_BASE_DIR=$${PACKER_OUTPUT_BASE_DIR:-.} CHECKPOINT_DISABLE=1 PACKER_LOG=1 PACKER_LOG_PATH=$@.log \
packer build -only=proxmox-ve-amd64-vsphere -on-error=abort -timestamp-ui $(VAR_FILE_OPTION) proxmox-ve-vsphere.json
CHECKPOINT_DISABLE=1 \
PACKER_LOG=1 \
PACKER_LOG_PATH=$@.init.log \
packer init proxmox-ve-vsphere.pkr.hcl
PACKER_OUTPUT_BASE_DIR=$${PACKER_OUTPUT_BASE_DIR:-.} \
CHECKPOINT_DISABLE=1 \
PACKER_LOG=1 \
PACKER_LOG_PATH=$@.log \
packer build -only=vsphere-iso.proxmox-ve-amd64 -on-error=abort -timestamp-ui $(VAR_FILE_OPTION) proxmox-ve-vsphere.pkr.hcl
rm -rf tmp/$@-contents
mkdir -p tmp/$@-contents
echo '{"provider":"vsphere"}' >tmp/$@-contents/metadata.json
cp Vagrantfile.template tmp/$@-contents/Vagrantfile
tar cvf $@ -C tmp/$@-contents .
@echo Box successfully built!
@echo to add it to vagrant run:
@echo vagrant box add -f proxmox-ve-amd64 $@
@./box-metadata.sh vsphere proxmox-ve-amd64 $@
clean:
rm -rf packer_cache $${PACKER_OUTPUT_BASE_DIR:-.}/output-proxmox-ve*

View File

@@ -182,17 +182,17 @@ Remember to also define `PACKER_OUTPUT_BASE_DIR` when you run `make clean` after
## Variables override
Some properties of the virtual machine and the Proxmox VE installation can be overridden.
Take a look at `proxmox-ve.json`, object `variables`, to get an idea which values can be
Take a look at `proxmox-ve.pkr.hcl`, `variable` blocks, to get an idea which values can be
overridden. Do not override `iso_url` and `iso_checksum` as the `boot_command`s might be
tied to a specific Proxmox VE version. Also take care when you decide to override `country`.
Create the base box:
```bash
make build-libvirt VAR_FILE=example.vars.json # or build-virtualbox or build-hyperv
make build-libvirt VAR_FILE=example.pkrvars.hcl # or build-virtualbox or build-hyperv
```
The following content of `example.vars.json`:
The following content of `example.pkrvars.hcl`:
* sets the initial disk size to 128 GB
* sets the initial memory to 4 GB
@@ -204,16 +204,21 @@ The following content of `example.vars.json`:
* uses all default shell provisioners (see [`./provisioners`](./provisioners)) and a
custom one for german localisation
```json
{
"disk_size": "131072",
"memory": "4096",
"output_base_dir": "/dev/shm",
"step_country": "Ger<wait>m<wait>a<wait>n<wait><enter>",
"step_hostname": "pve-test.example.local",
"step_keyboard_layout": "<end><up><wait>",
"shell_provisioner_scripts": "provisioners/apt_proxy.sh,provisioners/upgrade.sh,provisioners/network.sh,localisation-de.sh,provisioners/reboot.sh,provisioners/provision.sh"
}
```hcl
disk_size = 128 * 1024
memory = 4 * 1024
output_base_dir = "/dev/shm"
step_country = "Ger<wait>m<wait>a<wait>n<wait><enter>"
step_hostname = "pve-test.example.local"
step_keyboard_layout = "<end><up><wait>"
shell_provisioner_scripts = [
"provisioners/apt_proxy.sh",
"provisioners/upgrade.sh",
"provisioners/network.sh",
"provisioners/localisation-de.sh",
"provisioners/reboot.sh",
"provisioners/provision.sh",
]
```
# Packer boot_command

35
box-metadata.sh Executable file
View File

@@ -0,0 +1,35 @@
#!/bin/bash
set -euo pipefail
provider="$1"
name="$2"
path="$3"
# see https://developer.hashicorp.com/vagrant/docs/boxes/format#box-metadata
# see https://developer.hashicorp.com/vagrant/docs/boxes/format#box-file
# see https://github.com/hashicorp/packer-plugin-vagrant/blob/v1.0.3/post-processor/vagrant/libvirt.go#L100-L105
# see https://github.com/vagrant-libvirt/vagrant-libvirt/blob/0.11.2/spec/unit/action/handle_box_image_spec.rb#L96-L125
# see https://github.com/vagrant-libvirt/vagrant-libvirt/blob/0.11.2/lib/vagrant-libvirt/action/handle_box_image.rb
# see https://github.com/vagrant-libvirt/vagrant-libvirt/blob/0.11.2/docs/boxes.markdown
cat >"$path.json" <<EOF
{
"name": "$name",
"versions": [
{
"version": "0.0.0",
"providers": [
{
"name": "$provider",
"url": "$path"
}
]
}
]
}
EOF
cat <<EOF
Add the Vagrant Box with:
vagrant box add -f $name $path.json
EOF

View File

@@ -121,7 +121,7 @@ if [ "$(lsblk -no DISC-GRAN $(findmnt -no SOURCE /) | awk '{print $1}')" != '0B'
bytes_trimmed="$(echo "$output" | perl -n -e '/\((\d+) bytes\)/ && print $1')"
# NB if this never reaches zero, it might be because there is not
# enough free space for completing the trim.
if (( bytes_trimmed < $((16*1024*1024)) )); then # < 16 MiB is good enough.
if (( bytes_trimmed < $((100*1024*1024)) )); then # < 100 MiB is good enough.
break
fi
done

View File

@@ -1,108 +0,0 @@
{
"variables": {
"cpus": "2",
"memory": "2048",
"disk_size": "20480",
"vsphere_host": "{{env `GOVC_HOST`}}",
"vsphere_username": "{{env `GOVC_USERNAME`}}",
"vsphere_password": "{{env `GOVC_PASSWORD`}}",
"vsphere_esxi_host": "{{env `VSPHERE_ESXI_HOST`}}",
"vsphere_datacenter": "{{env `GOVC_DATACENTER`}}",
"vsphere_cluster": "{{env `GOVC_CLUSTER`}}",
"vsphere_datastore": "{{env `GOVC_DATASTORE`}}",
"vsphere_folder": "{{env `VSPHERE_TEMPLATE_FOLDER`}}",
"vsphere_network": "{{env `VSPHERE_VLAN`}}",
"vsphere_ip_wait_address": "{{env `VSPHERE_IP_WAIT_ADDRESS`}}",
"vsphere_os_iso": "{{env `VSPHERE_OS_ISO`}}",
"apt_cache_host": "{{env `APT_CACHE_HOST`}}",
"apt_cache_port": "{{env `APT_CACHE_PORT`}}",
"step_country": "United S<wait>t<wait>a<wait>t<wait>e<wait>s<wait><enter><wait>",
"step_email": "pve@example.com",
"step_hostname": "pve.example.com",
"step_keyboard_layout": "",
"step_timezone": "",
"shell_provisioner_scripts": "provisioners/apt_proxy.sh,provisioners/upgrade.sh,provisioners/network.sh,provisioners/localisation-pt.sh,provisioners/reboot.sh,provisioners/provision.sh"
},
"builders": [
{
"type": "vsphere-iso",
"name": "proxmox-ve-amd64-vsphere",
"vm_name": "proxmox-ve-amd64-vsphere",
"guest_os_type": "debian12_64Guest",
"NestedHV": true,
"CPUs": "{{user `cpus`}}",
"RAM": "{{user `memory`}}",
"datastore": "{{user `vsphere_datastore`}}",
"storage": [
{
"disk_size": "{{user `disk_size`}}",
"disk_thin_provisioned": true
}
],
"disk_controller_type": "pvscsi",
"iso_paths": [
"{{user `vsphere_os_iso`}}"
],
"network_adapters": [
{
"network": "{{user `vsphere_network`}}",
"network_card": "vmxnet3"
}
],
"vcenter_server": "{{user `vsphere_host`}}",
"username": "{{user `vsphere_username`}}",
"password": "{{user `vsphere_password`}}",
"insecure_connection": "true",
"datacenter": "{{user `vsphere_datacenter`}}",
"cluster": "{{user `vsphere_cluster`}}",
"host": "{{user `vsphere_esxi_host`}}",
"folder": "{{user `vsphere_folder`}}",
"convert_to_template": true,
"ssh_username": "root",
"ssh_password": "vagrant",
"ssh_timeout": "60m",
"boot_wait": "5s",
"boot_command": [
"<enter>",
"<wait1m>",
"<enter><wait>",
"<enter><wait>",
"{{user `step_country`}}<tab><wait>",
"{{user `step_timezone`}}<tab><wait>",
"{{user `step_keyboard_layout`}}<tab><wait>",
"<tab><wait>",
"<enter><wait5>",
"vagrant<tab><wait>",
"vagrant<tab><wait>",
"{{user `step_email`}}<tab><wait>",
"<tab><wait>",
"<enter><wait5>",
"{{user `step_hostname`}}<tab><wait>",
"<tab><wait>",
"<tab><wait>",
"<tab><wait>",
"<tab><wait>",
"<tab><wait>",
"<enter><wait5>",
"<enter><wait5>",
"<wait10m>",
"root<enter>vagrant<enter><wait5s>",
"apt-get update<enter><wait15s>",
"apt-get install -y open-vm-tools<enter><wait1m>",
"exit<enter>"
],
"shutdown_command": "poweroff"
}
],
"provisioners": [
{
"type": "shell",
"expect_disconnect": true,
"environment_vars": [
"apt_cache_host={{user `apt_cache_host`}}",
"apt_cache_port={{user `apt_cache_port`}}"
],
"scripts": "{{user `shell_provisioner_scripts`}}"
}
]
}

206
proxmox-ve-vsphere.pkr.hcl Normal file
View File

@@ -0,0 +1,206 @@
packer {
required_plugins {
# see https://github.com/hashicorp/packer-plugin-vsphere
vsphere = {
version = "1.2.1"
source = "github.com/hashicorp/vsphere"
}
}
}
variable "cpus" {
type = number
default = 2
}
variable "memory" {
type = number
default = 2 * 1024
}
variable "disk_size" {
type = number
default = 20 * 1024
}
variable "vsphere_os_iso" {
type = string
default = env("VSPHERE_OS_ISO")
}
variable "vsphere_host" {
type = string
default = env("GOVC_HOST")
}
variable "vsphere_username" {
type = string
default = env("GOVC_USERNAME")
}
variable "vsphere_password" {
type = string
default = env("GOVC_PASSWORD")
}
variable "vsphere_esxi_host" {
type = string
default = env("VSPHERE_ESXI_HOST")
}
variable "vsphere_datacenter" {
type = string
default = env("GOVC_DATACENTER")
}
variable "vsphere_cluster" {
type = string
default = env("GOVC_CLUSTER")
}
variable "vsphere_datastore" {
type = string
default = env("GOVC_DATASTORE")
}
variable "vsphere_folder" {
type = string
default = env("VSPHERE_TEMPLATE_FOLDER")
}
variable "vsphere_network" {
type = string
default = env("VSPHERE_VLAN")
}
variable "vsphere_ip_wait_address" {
type = string
default = env("VSPHERE_IP_WAIT_ADDRESS")
}
variable "apt_cache_host" {
type = string
default = env("APT_CACHE_HOST")
}
variable "apt_cache_port" {
type = string
default = env("APT_CACHE_PORT")
}
variable "step_country" {
type = string
default = "United S<wait>t<wait>a<wait>t<wait>e<wait>s<wait><enter><wait>"
}
variable "step_email" {
type = string
default = "pve@example.com"
}
variable "step_hostname" {
type = string
default = "pve.example.com"
}
variable "step_keyboard_layout" {
type = string
default = ""
}
variable "step_timezone" {
type = string
default = ""
}
variable "shell_provisioner_scripts" {
type = list(string)
default = [
"provisioners/apt_proxy.sh",
"provisioners/upgrade.sh",
"provisioners/network.sh",
"provisioners/localisation-pt.sh",
"provisioners/reboot.sh",
"provisioners/provision.sh",
]
}
source "vsphere-iso" "proxmox-ve-amd64" {
vm_name = "proxmox-ve-amd64"
http_directory = "."
guest_os_type = "debian12_64Guest"
NestedHV = true
CPUs = var.cpus
RAM = var.memory
storage {
disk_size = var.disk_size
disk_thin_provisioned = true
}
disk_controller_type = ["pvscsi"]
iso_paths = [
var.vsphere_os_iso,
]
vcenter_server = var.vsphere_host
username = var.vsphere_username
password = var.vsphere_password
insecure_connection = true
datacenter = var.vsphere_datacenter
cluster = var.vsphere_cluster
host = var.vsphere_esxi_host
folder = var.vsphere_folder
datastore = var.vsphere_datastore
network_adapters {
network = var.vsphere_network
network_card = "vmxnet3"
}
convert_to_template = true
ssh_username = "root"
ssh_password = "vagrant"
ssh_timeout = "60m"
boot_wait = "5s"
boot_command = [
"<enter>",
"<wait1m>",
"<enter><wait>",
"<enter><wait>",
"${var.step_country}<tab><wait>",
"${var.step_timezone}<tab><wait>",
"${var.step_keyboard_layout}<tab><wait>",
"<tab><wait>",
"<enter><wait5>",
"vagrant<tab><wait>",
"vagrant<tab><wait>",
"${var.step_email}<tab><wait>",
"<tab><wait>",
"<enter><wait5>",
"${var.step_hostname}<tab><wait>",
"<tab><wait>",
"<tab><wait>",
"<tab><wait>",
"<tab><wait>",
"<tab><wait>",
"<enter><wait5>",
"<enter><wait5>",
"<wait10m>",
"root<enter>vagrant<enter><wait5s>",
"apt-get update<enter><wait15s>",
"apt-get install -y open-vm-tools<enter><wait1m>",
"exit<enter>",
]
shutdown_command = "poweroff"
}
build {
sources = [
"source.vsphere-iso.proxmox-ve-amd64",
]
provisioner "shell" {
expect_disconnect = true
environment_vars = [
"apt_cache_host=${var.apt_cache_host}",
"apt_cache_port=${var.apt_cache_port}",
]
scripts = var.shell_provisioner_scripts
}
}

View File

@@ -1,264 +0,0 @@
{
"variables": {
"cpus": "2",
"memory": "2048",
"disk_size": "20480",
"iso_url": "http://download.proxmox.com/iso/proxmox-ve_8.0-2.iso",
"iso_checksum": "sha256:e2b27648a8a91c0da1e8e718882a5ff87a8f054c4dd7e0ea1d8af85125d82812",
"hyperv_switch_name": "{{env `HYPERV_SWITCH_NAME`}}",
"hyperv_vlan_id": "{{env `HYPERV_VLAN_ID`}}",
"apt_cache_host": "{{env `APT_CACHE_HOST`}}",
"apt_cache_port": "{{env `APT_CACHE_PORT`}}",
"output_base_dir": "{{env `PACKER_OUTPUT_BASE_DIR`}}",
"step_country": "United S<wait>t<wait>a<wait>t<wait>e<wait>s<wait><enter><wait>",
"step_email": "pve@example.com",
"step_hostname": "pve.example.com",
"step_keyboard_layout": "",
"step_timezone": "",
"shell_provisioner_scripts": "provisioners/apt_proxy.sh,provisioners/upgrade.sh,provisioners/network.sh,provisioners/localisation-pt.sh,provisioners/reboot.sh,provisioners/provision.sh"
},
"builders": [
{
"name": "proxmox-ve-amd64-libvirt",
"type": "qemu",
"accelerator": "kvm",
"cpus": "{{user `cpus`}}",
"memory": "{{user `memory`}}",
"qemuargs": [
["-cpu", "host"]
],
"headless": true,
"http_directory": ".",
"format": "qcow2",
"disk_size": "{{user `disk_size`}}",
"disk_interface": "virtio-scsi",
"disk_discard": "unmap",
"iso_url": "{{user `iso_url`}}",
"iso_checksum": "{{user `iso_checksum`}}",
"output_directory": "{{user `output_base_dir`}}/output-{{build_name}}",
"ssh_username": "root",
"ssh_password": "vagrant",
"ssh_timeout": "60m",
"boot_wait": "5s",
"boot_command": [
"<enter>",
"<wait1m>",
"<enter><wait>",
"<enter><wait>",
"{{user `step_country`}}<tab><wait>",
"{{user `step_timezone`}}<tab><wait>",
"{{user `step_keyboard_layout`}}<tab><wait>",
"<tab><wait>",
"<enter><wait5>",
"vagrant<tab><wait>",
"vagrant<tab><wait>",
"{{user `step_email`}}<tab><wait>",
"<tab><wait>",
"<enter><wait5>",
"{{user `step_hostname`}}<tab><wait>",
"<tab><wait>",
"<tab><wait>",
"<tab><wait>",
"<tab><wait>",
"<tab><wait>",
"<enter><wait5>",
"<enter><wait5>"
],
"shutdown_command": "poweroff"
},
{
"name": "proxmox-ve-uefi-amd64-libvirt",
"type": "qemu",
"accelerator": "kvm",
"cpus": "{{user `cpus`}}",
"memory": "{{user `memory`}}",
"qemuargs": [
["-bios", "/usr/share/ovmf/OVMF.fd"],
["-cpu", "host"]
],
"headless": true,
"http_directory": ".",
"format": "qcow2",
"disk_size": "{{user `disk_size`}}",
"disk_interface": "virtio-scsi",
"disk_discard": "unmap",
"iso_url": "{{user `iso_url`}}",
"iso_checksum": "{{user `iso_checksum`}}",
"output_directory": "{{user `output_base_dir`}}/output-{{build_name}}",
"ssh_username": "root",
"ssh_password": "vagrant",
"ssh_timeout": "60m",
"boot_wait": "5s",
"boot_command": [
"<enter>",
"<wait1m>",
"<enter><wait>",
"<enter><wait>",
"{{user `step_country`}}<tab><wait>",
"{{user `step_timezone`}}<tab><wait>",
"{{user `step_keyboard_layout`}}<tab><wait>",
"<tab><wait>",
"<enter><wait5>",
"vagrant<tab><wait>",
"vagrant<tab><wait>",
"{{user `step_email`}}<tab><wait>",
"<tab><wait>",
"<enter><wait5>",
"{{user `step_hostname`}}<tab><wait>",
"<tab><wait>",
"<tab><wait>",
"<tab><wait>",
"<tab><wait>",
"<tab><wait>",
"<enter><wait5>",
"<enter><wait5>"
],
"shutdown_command": "poweroff"
},
{
"name": "proxmox-ve-amd64-virtualbox",
"type": "virtualbox-iso",
"guest_os_type": "Debian_64",
"guest_additions_mode": "attach",
"headless": true,
"vboxmanage": [
["modifyvm", "{{.Name}}", "--memory", "{{user `memory`}}"],
["modifyvm", "{{.Name}}", "--cpus", "{{user `cpus`}}"],
["modifyvm", "{{.Name}}", "--nested-hw-virt", "on"],
["modifyvm", "{{.Name}}", "--vram", "16"],
["modifyvm", "{{.Name}}", "--graphicscontroller", "vmsvga"],
["modifyvm", "{{.Name}}", "--audio", "none"],
["modifyvm", "{{.Name}}", "--nictype1", "82540EM"],
["modifyvm", "{{.Name}}", "--nictype2", "82540EM"],
["modifyvm", "{{.Name}}", "--nictype3", "82540EM"],
["modifyvm", "{{.Name}}", "--nictype4", "82540EM"]
],
"vboxmanage_post": [
["storagectl", "{{.Name}}", "--name", "IDE Controller", "--remove"]
],
"disk_size": "{{user `disk_size`}}",
"hard_drive_interface": "sata",
"hard_drive_discard": true,
"iso_url": "{{user `iso_url`}}",
"iso_checksum": "{{user `iso_checksum`}}",
"output_directory": "{{user `output_base_dir`}}/output-{{build_name}}",
"ssh_username": "root",
"ssh_password": "vagrant",
"ssh_timeout": "60m",
"boot_wait": "5s",
"boot_command": [
"<enter>",
"<wait1m>",
"<enter><wait>",
"<enter><wait>",
"{{user `step_country`}}<tab><wait>",
"{{user `step_timezone`}}<tab><wait>",
"{{user `step_keyboard_layout`}}<tab><wait>",
"<tab><wait>",
"<enter><wait5>",
"vagrant<tab><wait>",
"vagrant<tab><wait>",
"{{user `step_email`}}<tab><wait>",
"<tab><wait>",
"<enter><wait5>",
"{{user `step_hostname`}}<tab><wait>",
"<tab><wait>",
"<tab><wait>",
"<tab><wait>",
"<tab><wait>",
"<tab><wait>",
"<enter><wait5>",
"<enter><wait5>"
],
"shutdown_command": "poweroff"
},
{
"name": "proxmox-ve-amd64-hyperv",
"type": "hyperv-iso",
"temp_path": "tmp",
"headless": true,
"generation": 2,
"enable_virtualization_extensions": true,
"enable_mac_spoofing": true,
"cpus": "{{user `cpus`}}",
"memory": "{{user `memory`}}",
"switch_name": "{{user `hyperv_switch_name`}}",
"vlan_id": "{{user `hyperv_vlan_id`}}",
"disk_size": "{{user `disk_size`}}",
"iso_url": "{{user `iso_url`}}",
"iso_checksum": "{{user `iso_checksum`}}",
"output_directory": "{{user `output_base_dir`}}/output-{{build_name}}",
"ssh_username": "root",
"ssh_password": "vagrant",
"ssh_timeout": "60m",
"first_boot_device": "DVD",
"boot_order": ["SCSI:0:0"],
"boot_wait": "5s",
"boot_command": [
"<enter>",
"<wait1m>",
"<enter><wait>",
"<enter><wait>",
"{{user `step_country`}}<tab><wait>",
"{{user `step_timezone`}}<tab><wait>",
"{{user `step_keyboard_layout`}}<tab><wait>",
"<tab><wait>",
"<enter><wait5>",
"vagrant<tab><wait>",
"vagrant<tab><wait>",
"{{user `step_email`}}<tab><wait>",
"<tab><wait>",
"<enter><wait5>",
"{{user `step_hostname`}}<tab><wait>",
"<tab><wait>",
"<tab><wait>",
"<tab><wait>",
"<tab><wait>",
"<tab><wait>",
"<enter><wait5>",
"<enter><wait5>",
"<wait4m>",
"root<enter>",
"<wait5>",
"vagrant<enter>",
"<wait5>",
"rm -f /etc/apt/sources.list.d/pve-enterprise.list<enter>",
"apt-get update<enter>",
"<wait1m>",
"apt-get install -y hyperv-daemons<enter>"
],
"shutdown_command": "poweroff"
}
],
"provisioners": [
{
"type": "shell",
"expect_disconnect": true,
"environment_vars": [
"apt_cache_host={{user `apt_cache_host`}}",
"apt_cache_port={{user `apt_cache_port`}}"
],
"scripts": "{{user `shell_provisioner_scripts`}}"
}
],
"post-processors": [
{
"type": "vagrant",
"output": "{{.BuildName}}.box",
"vagrantfile_template": "Vagrantfile.template",
"only": [
"proxmox-ve-amd64-libvirt",
"proxmox-ve-amd64-virtualbox",
"proxmox-ve-amd64-hyperv"
]
},
{
"type": "vagrant",
"output": "{{.BuildName}}.box",
"vagrantfile_template": "Vagrantfile-uefi.template",
"only": [
"proxmox-ve-uefi-amd64-libvirt"
]
}
]
}

367
proxmox-ve.pkr.hcl Normal file
View File

@@ -0,0 +1,367 @@
packer {
required_plugins {
# see https://github.com/hashicorp/packer-plugin-qemu
qemu = {
version = "1.0.9"
source = "github.com/hashicorp/qemu"
}
# see https://github.com/hashicorp/packer-plugin-virtualbox
virtualbox = {
version = "1.0.4"
source = "github.com/hashicorp/virtualbox"
}
# see https://github.com/hashicorp/packer-plugin-hyperv
hyperv = {
version = "1.1.0"
source = "github.com/hashicorp/hyperv"
}
# see https://github.com/hashicorp/packer-plugin-vagrant
vagrant = {
version = "1.0.3"
source = "github.com/hashicorp/vagrant"
}
}
}
variable "vagrant_box" {
type = string
}
variable "cpus" {
type = number
default = 2
}
variable "memory" {
type = number
default = 2 * 1024
}
variable "disk_size" {
type = number
default = 20 * 1024
}
variable "iso_url" {
type = string
default = "http://download.proxmox.com/iso/proxmox-ve_8.0-2.iso"
}
variable "iso_checksum" {
type = string
default = "sha256:e2b27648a8a91c0da1e8e718882a5ff87a8f054c4dd7e0ea1d8af85125d82812"
}
variable "hyperv_switch_name" {
type = string
default = env("HYPERV_SWITCH_NAME")
}
variable "hyperv_vlan_id" {
type = string
default = env("HYPERV_VLAN_ID")
}
variable "apt_cache_host" {
type = string
default = env("APT_CACHE_HOST")
}
variable "apt_cache_port" {
type = string
default = env("APT_CACHE_PORT")
}
variable "output_base_dir" {
type = string
default = env("PACKER_OUTPUT_BASE_DIR")
}
variable "step_country" {
type = string
default = "United S<wait>t<wait>a<wait>t<wait>e<wait>s<wait><enter><wait>"
}
variable "step_email" {
type = string
default = "pve@example.com"
}
variable "step_hostname" {
type = string
default = "pve.example.com"
}
variable "step_keyboard_layout" {
type = string
default = ""
}
variable "step_timezone" {
type = string
default = ""
}
variable "shell_provisioner_scripts" {
type = list(string)
default = [
"provisioners/apt_proxy.sh",
"provisioners/upgrade.sh",
"provisioners/network.sh",
"provisioners/localisation-pt.sh",
"provisioners/reboot.sh",
"provisioners/provision.sh",
]
}
source "qemu" "proxmox-ve-amd64" {
accelerator = "kvm"
machine_type = "q35"
cpus = var.cpus
memory = var.memory
qemuargs = [
["-cpu", "host"],
]
headless = true
use_default_display = false
net_device = "virtio-net"
http_directory = "."
format = "qcow2"
disk_size = var.disk_size
disk_interface = "virtio-scsi"
disk_cache = "unsafe"
disk_discard = "unmap"
iso_url = var.iso_url
iso_checksum = var.iso_checksum
output_directory = "${var.output_base_dir}/output-{{build_name}}"
ssh_username = "root"
ssh_password = "vagrant"
ssh_timeout = "60m"
boot_wait = "5s"
boot_command = [
"<enter>",
"<wait1m>",
"<enter><wait>",
"<enter><wait>",
"${var.step_country}<tab><wait>",
"${var.step_timezone}<tab><wait>",
"${var.step_keyboard_layout}<tab><wait>",
"<tab><wait>",
"<enter><wait5>",
"vagrant<tab><wait>",
"vagrant<tab><wait>",
"${var.step_email}<tab><wait>",
"<tab><wait>",
"<enter><wait5>",
"${var.step_hostname}<tab><wait>",
"<tab><wait>",
"<tab><wait>",
"<tab><wait>",
"<tab><wait>",
"<tab><wait>",
"<enter><wait5>",
"<enter><wait5>",
]
shutdown_command = "poweroff"
}
source "qemu" "proxmox-ve-uefi-amd64" {
accelerator = "kvm"
machine_type = "q35"
efi_boot = true
cpus = var.cpus
memory = var.memory
qemuargs = [
["-cpu", "host"],
]
headless = true
use_default_display = false
net_device = "virtio-net"
http_directory = "."
format = "qcow2"
disk_size = var.disk_size
disk_interface = "virtio-scsi"
disk_cache = "unsafe"
disk_discard = "unmap"
iso_url = var.iso_url
iso_checksum = var.iso_checksum
ssh_username = "root"
ssh_password = "vagrant"
ssh_timeout = "60m"
boot_wait = "10s"
boot_command = [
"<enter>",
"<wait1m>",
"<enter><wait>",
"<enter><wait>",
"${var.step_country}<tab><wait>",
"${var.step_timezone}<tab><wait>",
"${var.step_keyboard_layout}<tab><wait>",
"<tab><wait>",
"<enter><wait5>",
"vagrant<tab><wait>",
"vagrant<tab><wait>",
"${var.step_email}<tab><wait>",
"<tab><wait>",
"<enter><wait5>",
"${var.step_hostname}<tab><wait>",
"<tab><wait>",
"<tab><wait>",
"<tab><wait>",
"<tab><wait>",
"<tab><wait>",
"<enter><wait5>",
"<enter><wait5>",
]
shutdown_command = "poweroff"
}
source "virtualbox-iso" "proxmox-ve-amd64" {
guest_os_type = "Debian_64"
guest_additions_mode = "upload"
headless = true
http_directory = "."
vboxmanage = [
["modifyvm", "{{.Name}}", "--memory", var.memory],
["modifyvm", "{{.Name}}", "--cpus", var.cpus],
["modifyvm", "{{.Name}}", "--nested-hw-virt", "on"],
["modifyvm", "{{.Name}}", "--vram", "16"],
["modifyvm", "{{.Name}}", "--graphicscontroller", "vmsvga"],
["modifyvm", "{{.Name}}", "--audio", "none"],
["modifyvm", "{{.Name}}", "--nictype1", "82540EM"],
["modifyvm", "{{.Name}}", "--nictype2", "82540EM"],
["modifyvm", "{{.Name}}", "--nictype3", "82540EM"],
["modifyvm", "{{.Name}}", "--nictype4", "82540EM"],
]
vboxmanage_post = [
["storagectl", "{{.Name}}", "--name", "IDE Controller", "--remove"],
]
disk_size = var.disk_size
hard_drive_interface = "sata"
hard_drive_discard = true
iso_url = var.iso_url
iso_checksum = var.iso_checksum
output_directory = "${var.output_base_dir}/output-{{build_name}}"
ssh_username = "root"
ssh_password = "vagrant"
ssh_timeout = "60m"
boot_wait = "5s"
boot_command = [
"<enter>",
"<wait1m>",
"<enter><wait>",
"<enter><wait>",
"${var.step_country}<tab><wait>",
"${var.step_timezone}<tab><wait>",
"${var.step_keyboard_layout}<tab><wait>",
"<tab><wait>",
"<enter><wait5>",
"vagrant<tab><wait>",
"vagrant<tab><wait>",
"${var.step_email}<tab><wait>",
"<tab><wait>",
"<enter><wait5>",
"${var.step_hostname}<tab><wait>",
"<tab><wait>",
"<tab><wait>",
"<tab><wait>",
"<tab><wait>",
"<tab><wait>",
"<enter><wait5>",
"<enter><wait5>",
]
shutdown_command = "poweroff"
}
source "hyperv-iso" "proxmox-ve-amd64" {
temp_path = "tmp"
headless = true
http_directory = "."
generation = 2
enable_virtualization_extensions = true
enable_mac_spoofing = true
cpus = var.cpus
memory = var.memory
switch_name = var.hyperv_switch_name
vlan_id = var.hyperv_vlan_id
disk_size = var.disk_size
iso_url = var.iso_url
iso_checksum = var.iso_checksum
output_directory = "${var.output_base_dir}/output-{{build_name}}"
ssh_username = "root"
ssh_password = "vagrant"
ssh_timeout = "60m"
first_boot_device = "DVD"
boot_order = ["SCSI:0:0"]
boot_wait = "5s"
boot_command = [
"<enter>",
"<wait1m>",
"<enter><wait>",
"<enter><wait>",
"${var.step_country}<tab><wait>",
"${var.step_timezone}<tab><wait>",
"${var.step_keyboard_layout}<tab><wait>",
"<tab><wait>",
"<enter><wait5>",
"vagrant<tab><wait>",
"vagrant<tab><wait>",
"${var.step_email}<tab><wait>",
"<tab><wait>",
"<enter><wait5>",
"${var.step_hostname}<tab><wait>",
"<tab><wait>",
"<tab><wait>",
"<tab><wait>",
"<tab><wait>",
"<tab><wait>",
"<enter><wait5>",
"<enter><wait5>",
"<wait4m>",
"root<enter>",
"<wait5>",
"vagrant<enter>",
"<wait5>",
"rm -f /etc/apt/sources.list.d/pve-enterprise.list<enter>",
"apt-get update<enter>",
"<wait1m>",
"apt-get install -y hyperv-daemons<enter>",
]
shutdown_command = "poweroff"
}
build {
sources = [
"source.qemu.proxmox-ve-amd64",
"source.qemu.proxmox-ve-uefi-amd64",
"source.virtualbox-iso.proxmox-ve-amd64",
"source.hyperv-iso.proxmox-ve-amd64",
]
provisioner "shell" {
expect_disconnect = true
environment_vars = [
"apt_cache_host=${var.apt_cache_host}",
"apt_cache_port=${var.apt_cache_port}",
]
scripts = var.shell_provisioner_scripts
}
post-processor "vagrant" {
only = [
"qemu.proxmox-ve-amd64",
"hyperv-iso.proxmox-ve-amd64",
"virtualbox-iso.proxmox-ve-amd64",
]
output = var.vagrant_box
vagrantfile_template = "Vagrantfile.template"
}
post-processor "vagrant" {
only = [
"qemu.proxmox-ve-uefi-amd64",
]
output = var.vagrant_box
vagrantfile_template = "Vagrantfile-uefi.template"
}
}