Skip to content

Commit

Permalink
Add a set of working VMware Fusion examples (#130)
Browse files Browse the repository at this point in the history
* Add example templates for Fusion v12 and v13

* Create initial template bundle structure with pkrvar files
* Add variable for memory
* Update preseed configuration
* Add adapter types to config
* Add output directory for each build

Co-authored-by: Lucas Bajolet <105649352+lbajolet-hashicorp@users.noreply.github.com>
  • Loading branch information
nywilken and lbajolet-hashicorp authored Apr 17, 2023
1 parent 399fb62 commit 6635f99
Show file tree
Hide file tree
Showing 10 changed files with 335 additions and 57 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
main
dist/*
packer-plugin-vmware
example/output-example/
example/builds/*/
.DS_Store
.docs
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ Matrix from General Availability to End of General Support. Learn more:

Required if building the plugin.

## Usage

For a few examples on how to use this plugin with Packer refer to the [example](example/) template directory.
## Installation

### Using Pre-built Releases
Expand Down
41 changes: 41 additions & 0 deletions example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# VMware Packer Plugin Examples

This directory contains a set of templates to illustrate how to run the plugin for different versions of VMware products,
as VMware ESXi, VMware Fusion, VMware Player, and VMware Workstation all work slightly differently.

_Big thanks to @tenthirtyam and @Stromweld for their help in getting these templates working._

## Example Directory Structure
The source files are spread across multiple files:
- source.pkr.hcl contains the source block definition for the build image.
- variables.pkr.hcl contains a set of defined variables needed for building the image.
- build.pkr.hcl is the main entry point for Packer to build the VMware image defined in source.pkr.hcl.
- pkrvars/ contains a set of Packer variable definition files (*.pkrvars.hcl) partitioned by guest_os/vmware-version.

## Running VMware Fusion Examples
> **Note**
>
> VMware Fusion 13 does not support lsilogic adapter types and require additional vmx_data configurations for supporting ARM based builds.
> Below are the adapter types and addition vmx_data configuration options that have been found to work.
> ```
> vmx_data = {
> "svga.autodetect" = true
> "usb_xhci.present" = true
> }
> cdrom_adapter_type = "sata"
> disk_adapter_type = "sata"
> ```
> Please refer to the [Fusion 13 pkvars.hcl file](pkrvars/debian/fusion-13.pkrvars.hcl) for exact details.
**For Fusion 12 builds**
```shell
packer init .
packer build -var-file=pkrvars/debian/fusion-12.pkrvars.hcl .
```

**For Fusion 13 builds**
```shell
packer init .
packer build -var-file=pkrvars/debian/fusion-13.pkrvars.hcl .
```

23 changes: 9 additions & 14 deletions example/build.pkr.hcl
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
# Copyright (c) HashiCorp, Inc.
# SPDX-License-Identifier: MPL-2.0

source "vmware-iso" "example" {
boot_command = ["<esc><wait>", "<esc><wait>", "<enter><wait>", "/install/vmlinuz<wait>", " initrd=/install/initrd.gz", " auto-install/enable=true", " debconf/priority=critical", " preseed/url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/preseed.cfg<wait>", " -- <wait>", "<enter><wait>"]
boot_wait = "10s"
guest_os_type = "ubuntu-64"
headless = true
http_directory = "${path.root}/http"
iso_checksum = "sha256:946a6077af6f5f95a51f82fdc44051c7aa19f9cfc5f737954845a6050543d7c2"
iso_url = "http://old-releases.ubuntu.com/releases/14.04.1/ubuntu-14.04.1-server-amd64.iso"
shutdown_command = "echo 'vagrant' | sudo -S shutdown -P now"
ssh_password = "vagrant"
ssh_timeout = "10000s"
ssh_username = "vagrant"
tools_upload_flavor = "linux"
packer {
required_version = ">= 1.7.0"
required_plugins {
vmware = {
version = ">= 1.0.7"
source = "github.com/hashicorp/vmware"
}
}
}

build {
sources = ["source.vmware-iso.example"]
sources = ["source.vmware-iso.debian"]
}
104 changes: 104 additions & 0 deletions example/data/debian/preseed.pkrtpl.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
#_preseed_V1
# Automatic installation
d-i auto-install/enable boolean true

# Preseeding only locale sets language, country and locale.
d-i debian-installer/language string ${vm_guest_os_language}
d-i debian-installer/country string US
d-i debian-installer/locale string en_US.UTF-8

d-i console-setup/ask_detect boolean false
d-i debconf/frontend select noninteractive

# Keyboard selection.
d-i keyboard-configuration/xkb-keymap select ${vm_guest_os_keyboard}
d-i keymap select ${vm_guest_os_keyboard}

choose-mirror-bin mirror/http/proxy string
d-i apt-setup/use_mirror boolean true
d-i base-installer/kernel/override-image string linux-server

### Clock and time zone setup
d-i clock-setup/utc boolean true
d-i clock-setup/utc-auto boolean true
d-i time/zone string ${vm_guest_os_timezone}

# Avoid that last message about the install being complete.
d-i finish-install/reboot_in_progress note

# This is fairly safe to set, it makes grub install automatically to the MBR
# if no other operating system is detected on the machine.
d-i grub-installer/only_debian boolean true

# This one makes grub-installer install to the MBR if it also finds some other
# OS, which is less safe as it might not be able to boot that other OS.
d-i grub-installer/with_other_os boolean true

# Set dev for grub boot
d-i grub-installer/bootdev string /dev/sda

### Mirror settings
# If you select ftp, the mirror/country string does not need to be set.
d-i mirror/country string manual
d-i mirror/http/directory string /debian/
d-i mirror/http/hostname string httpredir.debian.org
d-i mirror/http/proxy string

# This makes partman automatically partition without confirmation.
d-i partman-efi/non_efi_system boolean true
d-i partman-auto-lvm/guided_size string max
d-i partman-auto/choose_recipe select atomic
d-i partman-auto/method string lvm
d-i partman-lvm/confirm boolean true
d-i partman-lvm/confirm_nooverwrite boolean true
d-i partman-lvm/device_remove_lvm boolean true
d-i partman/choose_partition select finish
d-i partman/confirm boolean true
d-i partman/confirm_nooverwrite boolean true
d-i partman/confirm_write_new_label boolean true

### Account setup
d-i passwd/root-login boolean false
d-i passwd/user-fullname string ${build_username}
d-i passwd/username string ${build_username}
d-i passwd/user-uid string 1000
d-i passwd/user-password password ${build_password}
d-i passwd/user-password-again password ${build_password}

# The installer will warn about weak passwords. If you are sure you know
# what you're doing and want to override it, uncomment this.
d-i user-setup/allow-password-weak boolean true
d-i user-setup/encrypt-home boolean false

### Package selection
tasksel tasksel/first multiselect standard, ssh-server
d-i pkgsel/include string openssh-server sudo bzip2 acpid cryptsetup zlib1g-dev wget curl dkms fuse make nfs-common net-tools cifs-utils rsync
d-i pkgsel/install-language-support boolean false

# Prevent packaged version of VirtualBox Guest Additions being installed:
d-i preseed/early_command string sed -i \
'/in-target/idiscover(){/sbin/discover|grep -v VirtualBox;}' \
/usr/lib/pre-pkgsel.d/20install-hwpackages

# Do not scan additional CDs
apt-cdrom-setup apt-setup/cdrom/set-first boolean false

# Use network mirror
apt-mirror-setup apt-setup/use_mirror boolean true

# disable automatic package updates
d-i pkgsel/update-policy select none
d-i pkgsel/upgrade select full-upgrade

# Disable polularity contest
popularity-contest popularity-contest/participate boolean false

# Select base install
tasksel tasksel/first multiselect standard, ssh-server

# Setup passwordless sudo for packer user
d-i preseed/late_command string \
echo "vagrant ALL=(ALL:ALL) NOPASSWD:ALL" > /target/etc/sudoers.d/vagrant && chmod 0440 /target/etc/sudoers.d/vagrant

# remove cdrom from apt sources
d-i preseed/late_command string sed -i '/^deb cdrom:/s/^/#/' /target/etc/apt/sources.list
42 changes: 0 additions & 42 deletions example/http/preseed.cfg

This file was deleted.

8 changes: 8 additions & 0 deletions example/pkrvars/debian/fusion-12.pkrvars.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
iso_url = "https://cdimage.debian.org/debian-cd/current/amd64/iso-dvd/debian-11.6.0-amd64-DVD-1.iso"
iso_checksum = "55f6f49b32d3797621297a9481a6cc3e21b3142f57d8e1279412ff5a267868d8"
data_directory = "data/debian"
guest_os_type = "debian-64"
hardware_version = 19
boot_command = ["<wait><esc><wait>auto preseed/url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/preseed.cfg netcfg/get_hostname={{ .Name }}<enter>"]
vm_name = "debian_x86_64"

18 changes: 18 additions & 0 deletions example/pkrvars/debian/fusion-13.pkrvars.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
cdrom_adapter_type = "sata"
data_directory = "data/debian"
disk_adapter_type = "sata"
network_adapter_type = "e1000e"
iso_url = "https://cdimage.debian.org/debian-cd/current/arm64/iso-dvd/debian-11.6.0-arm64-DVD-1.iso"
iso_checksum = "b27ff768c10808518790d72d670c5588cdc60cf8934ef92773a89274a193a65f"
guest_os_type = "arm-debian-64"
hardware_version = 20
boot_command = ["<wait><up>e<wait><down><down><down><right><right><right><right><right><right><right><right><right><right><right><right><right><right><right><right><right><right><right><right><right><right><right><right><right><right><right><right><right><right><right><right><right><right><wait>install <wait> preseed/url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/preseed.cfg <wait>debian-installer=en_US.UTF-8 <wait>auto <wait>locale=en_US.UTF-8 <wait>kbd-chooser/method=us <wait>keyboard-configuration/xkb-keymap=us <wait>netcfg/get_hostname={{ .Name }} <wait>netcfg/get_domain={{ .Name }} <wait>fb=false <wait>debconf/frontend=noninteractive <wait>console-setup/ask_detect=false <wait>console-keymaps-at/keymap=us <wait>grub-installer/bootdev=/dev/sda <wait><f10><wait>"]
vm_name = "debian_aarch64"
vmx_data = {
"cpuid.coresPerSocket" = "2"
"ethernet0.pciSlotNumber" = "32"
"svga.autodetect" = true
"usb_xhci.present" = true
}


40 changes: 40 additions & 0 deletions example/sources.pkr.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Copyright (c) HashiCorp, Inc.
# SPDX-License-Identifier: MPL-2.0

locals {
data_directory = var.data_directory == null ? "data" : var.data_directory
memory = var.memory == null ? 2048 : var.memory
}

source "vmware-iso" "debian" {
boot_command = var.boot_command
boot_wait = "10s"
cpus = 2
cdrom_adapter_type = var.cdrom_adapter_type
disk_adapter_type = var.disk_adapter_type
guest_os_type = var.guest_os_type
headless = var.vm_headless
http_content = { # Use http_content template to dynamic configure preseed - https://www.hashicorp.com/blog/using-template-files-with-hashicorp-packer
"/preseed.cfg" = templatefile("${abspath(path.root)}/${local.data_directory}/preseed.pkrtpl.hcl", {
build_username = var.build_username
build_password = var.build_password
vm_guest_os_language = var.vm_guest_os_language
vm_guest_os_keyboard = var.vm_guest_os_keyboard
vm_guest_os_timezone = var.vm_guest_os_timezone
})
}
iso_checksum = var.iso_checksum
iso_url = var.iso_url
memory = local.memory
network_adapter_type = var.network_adapter_type
output_directory = "builds/${var.vm_name}"
shutdown_command = "echo 'vagrant' | sudo -S shutdown -P now"
ssh_password = "vagrant"
ssh_timeout = "10000s"
ssh_username = "vagrant"
tools_upload_flavor = var.tools_upload_flavor
tools_upload_path = var.tools_upload_path
version = var.hardware_version
vmx_data = var.vmx_data
}

Loading

0 comments on commit 6635f99

Please sign in to comment.