I am working on a Debian packer template for vSphere. In order to use variables in the preseed file, I am trying to generate it from a template using an http_content block with templatefile(), but when I build it, everything in my http_content block is ignored. The HTTP server goes up as expected, but the preseed.cfg file is not generated, and I get no errors, warnings, or other output indicating that packer is in any way unhappy with my code. Everything goes smoothly until the Debian installer tries to access the preseed file and throws an error because the file isn’t present on the HTTP server. Meanwhile, packer sits on “Waiting for IP…”
I’m out of ideas. Am I missing something? My packer build machine is a Debian 12 box with packer 1.14.2 and version 2.0.0 of the vSphere plugin. Here is my build template:
packer {
required_plugins {
vsphere = {
version = ">= 1.7.0"
source = "github.com/hashicorp/vsphere"
}
}
}
locals {
cidata_content = {
"/meta-data" = file("${abspath(path.root)}/data/meta-data")
"/user-data" = templatefile("${abspath(path.root)}/data/user-data.pkrtpl.hcl", {
build_fullname = var.build_fullname
build_username = var.build_username
ssh_public_keys = var.ssh_public_keys
})
}
}
source "vsphere-iso" "_P-DEBIAN-13" {
vcenter_server = var.vsphere_server
username = var.vsphere_user
password = var.vsphere_password
datacenter = var.datacenter
cluster = var.cluster
folder = var.vsphere_folder
insecure_connection = false
vm_name = "_P-DEBIAN-13"
guest_os_type = "other6xLinux64Guest"
firmware = "efi-secure"
vvtd_enabled = var.vvtd_enabled
NestedHV = var.nested_hv
vbs_enabled = var.vbs_enabled
CPUs = 2
cpu_cores = 0
RAM = 4096
RAM_reserve_all = false
convert_to_template = true
communicator = "ssh"
ssh_username = var.build_username
ssh_agent_auth = true
ssh_timeout = "30m"
ssh_pty = true
disk_controller_type = ["pvscsi"]
datastore = var.datastore
storage {
disk_size = 107374
disk_thin_provisioned = true
}
iso_paths = ["[DATASTORE] ISOs/debian-13.0.0-amd64-netinst.iso"]
network_adapters {
network = var.network_name
network_card = "vmxnet3"
}
configuration_parameters = {
"isolation.tools.copy.disable" = "FALSE"
"isolation.tools.paste.disable" = "FALSE"
"isolation.tools.setGUIOptions.enable" = "TRUE"
"isolation.tools.paste.disable" = "FALSE"
"isolation.tools.setGUIOptions.enable" = "TRUE"
}
# cd_files = ["./data/meta-data", "./data/user-data"]
cd_content = local.cidata_content
cd_label = "cidata"
boot_command = [
"<esc><wait>",
"<down>e",
"<down><down><down><end>",
"DEBCONF_DEBUG=5 ",
"auto=true ",
"interface=auto ",
"netcfg/disable_dhcp=true ",
"netcfg/get_ipaddress=xxx.xxx.xxx.xxx ",
"netcfg/get_netmask=255.255.255.0 ",
"netcfg/get_gateway=xxx.xxx.xxx.xxx ",
"netcfg/get_nameservers=xxx.xxx.xxx.xxx ",
"hostname={{ .Name }} domain=example.com ",
"preseed/url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/preseed.cfg",
"<f10>"
]
http_content = {
"preseed.cfg" = templatefile("${abspath(path.root)}/preseed.pkrtpl", {
fullname = var.build_fullname
username = var.build_username
password = var.build_password
})
}
}
build {
sources = ["source.vsphere-iso._P-DEBIAN-13"]
provisioner "shell" {
inline = [
"sudo apt update && sudo apt upgrade -y",
"sudo rm /etc/ssh/ssh_host_*",
"sudo rm -f /var/lib/systemd/random-seed",
"sudo cloud-init clean --machine-id -c all --logs"
]
}
}