Hi, below my .pkr.hcl file.
Remember that it is tested only for this:
For packer v1.6.6 / vsphere 7.0 / ubuntu-20.04.1-live-server-amd64.iso / packer vsphere-iso builder.
What I did to find a working configuration was to create a VM in the vCenter Server without packer. I attached two cd rom drives. One with the ubuntu installer iso and a second cd rom drive with user-data and meta-data on it.
In my case the ubuntu installer was able to read the user-data but later during installation it complained that the command ‘autoinstall’ was missing. After this it was easy to craft the below boot_command.
To create an iso image with user-data and meta-data on it you can simply start packer with the -debug flag. Proceed to the point where packer has created the iso and stored it in the datastore. Then go to the datastore and download the iso and use it in the above scenario. To validate your iso just mount it somewhere and check if user-data and meta-data are there.
Hope this helps
Best Roland
source "vsphere-iso" "bastionserver" {
vcenter_server = "*****"
username = *****
password = var.vsphere_password
insecure_connection = "true"
host = "****"
datastore = "******"
vm_name = "bastionserver-template"
CPUs = 2
RAM = 2000
guest_os_type = "ubuntu64Guest"
network_adapters {
network = "VM Network"
network_card = "vmxnet3"
mac_address = "00:50:56:00:00:01"
}
storage {
disk_size = 20000
disk_thin_provisioned = true
}
boot_order = "disk,cdrom"
convert_to_template = true
iso_paths = [
"[qnap-vm-datastore-1] /iso-images/ubuntu-20.04.1-live-server-amd64.iso"
]
cd_files = [
"./cloud-init/meta-data",
"./cloud-init/user-data"]
cd_label = "cidata"
boot_wait = "2s"
boot_command = [
"<esc><esc><esc>",
"<enter><wait>",
"/casper/vmlinuz ",
"initrd=/casper/initrd ",
"autoinstall ",
"<enter>"
]
ssh_username = "******"
ssh_password = var.ssh_password
ssh_pty = true
ssh_timeout = "20m"
ssh_handshake_attempts = "20"
}
build {
sources = [
"source.vsphere-iso.bastionserver"]
provisioner "shell" {
...
...