packer { required_plugins { } } source "vsphere-iso" "k8sbootstrap" { vcenter_server = var.vcenter_server username = var.vsphere_username password = var.vsphere_password insecure_connection = "true" vm_name = "${var.vm_guestos}-${var.vm_name}" datacenter = var.vsphere_datacenter cluster = var.vsphere_cluster host = var.vsphere_host folder = var.vsphere_folder datastore = var.vsphere_datastore guest_os_type = "ubuntu64Guest" boot_order = "disk,cdrom" boot_command = [ "e", " autoinstall ds=nocloud;", "" ] boot_wait = "2s" communicator = "ssh" ssh_username = "ubuntu" ssh_password = var.ssh_password ssh_timeout = "20m" ssh_handshake_attempts = "100" ssh_pty = true CPUs = 2 RAM = 4096 network_adapters { network = var.vsphere_network network_card = "vmxnet3" } storage { disk_size = 20480 disk_thin_provisioned = true } disk_controller_type = ["pvscsi"] usb_controller = ["xhci"] cd_files = [ "packer/preseed/UbuntuServer22.04/user-data", "packer/preseed/UbuntuServer22.04/meta-data" ] cd_label = "cidata" iso_url = local.iso_authenticatedurl iso_checksum = var.iso_checksum shutdown_command = "echo '${var.ssh_password}' | sudo -S shutdown -P now" shutdown_timeout = "5m" export { images = false output_directory = "/scratch/k8sbootstrap" } remove_cdrom = true } build { sources = [ "source.vsphere-iso.k8sbootstrap" ] provisioner "ansible" { pause_before = "2m30s" playbook_file = "ansible/playbook.yml" user = "ubuntu" ansible_env_vars = [ "ANSIBLE_CONFIG=ansible/ansible.cfg" ] use_proxy = "false" extra_arguments = [ "--extra-vars", "ansible_ssh_pass=${var.ssh_password}" ] } post-processor "shell-local" { inline = [ "pwsh -command \"& scripts/Update-OvfConfiguration.ps1 \\", " -OVFFile '/scratch/k8sbootstrap/${var.vm_guestos}-${var.vm_name}.ovf' \\", " -Parameter @{'appliance.name'='${var.vm_guestos}';'appliance.version'='${var.vm_name}'}\"", "pwsh -file scripts/Update-Manifest.ps1 \\", " -ManifestFileName '/scratch/k8sbootstrap/${var.vm_guestos}-${var.vm_name}.mf'", "ovftool --acceptAllEulas --allowExtraConfig --overwrite \\", " '/scratch/k8sbootstrap/${var.vm_guestos}-${var.vm_name}.ovf' \\", " /output/Kubernetes.Bootstrap.Appliance.ova" ] } }