From b340c777baf052b32d1f301ba35710107b7afbc2 Mon Sep 17 00:00:00 2001 From: djpbessems Date: Thu, 17 Jun 2021 11:21:22 +0200 Subject: [PATCH] Create rawdisk image for baremetal provisioning --- packer/ubuntuserver20.04.pkr.hcl | 89 ++++++++++++++++++++++++++++++-- 1 file changed, 84 insertions(+), 5 deletions(-) diff --git a/packer/ubuntuserver20.04.pkr.hcl b/packer/ubuntuserver20.04.pkr.hcl index 08b90af..858f65f 100644 --- a/packer/ubuntuserver20.04.pkr.hcl +++ b/packer/ubuntuserver20.04.pkr.hcl @@ -16,7 +16,7 @@ source "vsphere-iso" "ubuntuserver" { datastore = var.vsphere_datastore guest_os_type = "ubuntu64Guest" - + boot_order = "disk,cdrom" boot_command = [ "", @@ -24,17 +24,17 @@ source "vsphere-iso" "ubuntuserver" { "" ] 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" @@ -63,11 +63,76 @@ source "vsphere-iso" "ubuntuserver" { } remove_cdrom = true } +source "vsphere-iso" "ubuntuserver-baremetal" { + vcenter_server = var.vcenter_server + username = var.vsphere_username + password = var.vsphere_password + insecure_connection = "true" + + vm_name = "${var.vm_guestos}-${var.vm_name}-baremetal" + datacenter = var.vsphere_datacenter + host = var.vsphere_host + folder = var.vsphere_folder + datastore = var.vsphere_datastore + + guest_os_type = "ubuntu64Guest" + + boot_order = "disk,cdrom" + boot_command = [ + "", + " 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/UbuntuServer20.04/user-data", + "packer/preseed/UbuntuServer20.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/ubuntuserver-baremetal" + } + remove_cdrom = true +} build { - sources = ["source.vsphere-iso.ubuntuserver"] + sources = [ + "source.vsphere-iso.ubuntuserver", + "source.vsphere-iso.ubuntuserver-baremetal" + ] provisioner "ansible" { + only = ["source.vsphere-iso.ubuntuserver"] + playbook_file = "ansible/playbook.yml" user = "ubuntu" ansible_env_vars = [ @@ -80,6 +145,7 @@ build { } post-processor "shell-local" { + only = ["source.vsphere0iso.ubuntuserver"] inline = [ "pwsh -command \"& scripts/Update-OvfConfiguration.ps1 \\", " -OVFFile '/scratch/ubuntuserver/${var.vm_guestos}-${var.vm_name}.ovf' \\", @@ -91,4 +157,17 @@ build { " /output/Ubuntu-Server-20.04.ova" ] } + post-processor "shell-local" { + only = ["source.vsphere0iso.ubuntuserver-baremetal"] + inline = [ +"ls /scratch/ubuntuserver-baremetal -lash", + "qemu-img convert -f vmdk -o raw \", + " /scratch/ubuntuserver-baremetal/${var.vm_guestos}-${var.vm_name}-disk001.vmdk \", + " /scratch/ubuntuserver-baremetal/${var.vm_guestos}-${var.vm_name}.raw", +"ls /scratch/ubuntuserver-baremetal -lash", + "gzip -c \", + " /scratch/ubuntuserver-baremetal/${var.vm_guestos}-${var.vm_name}.raw \", + " > /output/Ubuntu-Server-20.04.raw.gz" + ] + } } \ No newline at end of file