diff --git a/packer.pkr.hcl b/packer.pkr.hcl index 0d5721b..17518e1 100644 --- a/packer.pkr.hcl +++ b/packer.pkr.hcl @@ -22,7 +22,7 @@ packer { source = "github.com/hashicorp/proxmox" } vmware = { - version = ">= 1.0.0" + version = ">= 1.0.7" source = "github.com/hashicorp/vmware" } virtualbox = { @@ -157,14 +157,18 @@ source "vmware-iso" "controller" { http_directory = "kickstart" iso_checksum = "${var.iso_checksum}" iso_urls = ["${var.iso_url1}", "${var.iso_url2}"] - output_directory = "output-vmware-iso" + output_directory = "output-images" shutdown_command = "echo 'vagrant' | sudo -S /sbin/shutdown -h 0" ssh_password = "vagrant" - ssh_username = "root" + ssh_username = "vagrant" ssh_wait_timeout = "10000s" tools_upload_flavor = "linux" vm_name = "controller" vmdk_name = "controller" + vmx_data = { + "svga.autodetect" = true + "usb_xhci.present" = true + } } # https://developer.hashicorp.com/packer/plugins/builders/hyperv/iso @@ -208,10 +212,15 @@ build { sources = ["source.azure-arm.controller", "source.hyperv-iso.controller", "source.virtualbox-iso.controller", "source.vmware-iso.controller"] provisioner "shell" { - except = ["azure-arm.controller"] + except = ["azure-arm.controller"] execute_command = "bash '{{ .Path }}'" script = "vagrant.sh" } + provisioner "shell" { + except = ["azure-arm.controller"] + execute_command = "bash '{{ .Path }}'" + script = "vmtools.sh" + } provisioner "shell" { execute_command = "echo 'vagrant' | {{ .Vars }} sudo -S -E bash '{{ .Path }}'" scripts = ["controller.sh"] diff --git a/vmtools.sh b/vmtools.sh new file mode 100644 index 0000000..5222025 --- /dev/null +++ b/vmtools.sh @@ -0,0 +1,50 @@ +#!/bin/sh -eux + +# set a default HOME_DIR environment variable if not set +HOME_DIR=/root + +case "$PACKER_BUILDER_TYPE" in + + virtualbox-iso|virtualbox-ovf) + yum install -y bzip2 tar gcc make perl cpp libstdc++-devel kernel-devel kernel-headers + + mkdir -p /tmp/vbox /run/vboxadd + chown vboxadd /run/vboxadd + chmod 700 /run/vboxadd + mount -o loop $HOME_DIR/VBoxGuestAdditions.iso /tmp/vbox; + sh /tmp/vbox/VBoxLinuxAdditions.run \ + || echo "VBoxLinuxAdditions.run exited $? and is suppressed." \ + "For more read https://www.virtualbox.org/ticket/12479"; + umount /tmp/vbox; + rm -rf /tmp/vbox; + rm -f $HOME_DIR/*.iso; + + yum -y erase gcc make perl cpp libstdc++-devel kernel-devel kernel-headers + yum -y clean all + + ## https://access.redhat.com/site/solutions/58625 (subscription required) + # add 'single-request-reopen' so it is included when /etc/resolv.conf is generated + echo 'RES_OPTIONS="single-request-reopen"' >> /etc/sysconfig/network + service network restart + echo 'Slow DNS fix applied (single-request-reopen)' + + ;; + +vmware-iso|vmware-vmx) + yum install -y perl fuse-utils + mkdir -p /tmp/vmware + mkdir -p /tmp/vmware-archive + mount -o loop $HOME_DIR/linux.iso /tmp/vmware + tar xzf /tmp/vmware/VMwareTools-*.tar.gz -C /tmp/vmware-archive + /tmp/vmware-archive/vmware-tools-distrib/vmware-install.pl --default + umount /tmp/vmware; + rm -rf /tmp/vmware; + rm -rf /tmp/vmware-archive; + rm -f $HOME_DIR/*.iso; + ;; + +*) + echo "No guest additions implemented for ${PACKER_BUILDER_TYPE}" + ;; + +esac