Skip to content

Build

Build Script Options

If you need help for script options, pass the --help or -h flag to the build script to display the help for the build script.

./build.sh --help

If you need to enable debugging, pass the --debug or -d flag to the build script to enable debug mode for Packer.

This example will look for the configuration files in the config directory and enable debug mode for Packer.

./build.sh --debug

This example will look for the configuration files in the us-west-1 directory and enable debug mode for Packer.

./build.sh --debug us-west-1

Using the Build Script

Build with Defaults

Start a build by running the build script (./build.sh). The script presents a menu the which simply calls Packer and the respective build(s).

This example will look for the configuration files in the config directory.

./build.sh

Build a Specific Configuration

This example will look for the configuration files in the us-west-1 directory.

./build.sh us-west-1

Generate a Custom Build Script

The build script (./build.sh) can be generated with Gomplate using a template (./build.tmpl) and a configuration file in YAML (./build.yaml).

Generate a custom build script:

gomplate -c build.yaml -f build.tmpl -o build.sh

or

make update-build-script

Build Directly with Packer

You can also start a build based on a specific source for some of the virtual machine images.

For example, if you simply want to build a Microsoft Windows Server 2022 Standard Core, run the following:

Initialize the plugins:

packer init builds/windows/server/2022/.

Build a specific machine image:

packer build -force on-error=ask \
    --only vsphere-iso.windows-server-standard-core \
    -var-file="config/build.pkrvars.hcl" \
    -var-file="config/common.pkrvars.hcl" \
    -var-file="config/vsphere.pkrvars.hcl" \
    builds/windows/server/2022

➜ packer validate \ -var-file="config/ansible.pkrvars.hcl" \ -var-file="config/build.pkrvars.hcl" \ -var-file="config/common.pkrvars.hcl" \ -var-file="config/proxy.pkrvars.hcl" \ -var-file="config/vsphere.pkrvars.hcl" \ builds/linux/photon/5

Build with Environmental Variables

You can set your environment variables if you would prefer not to save sensitive information in clear-text files.

You can add these to environmental variables using the included set-envvars.sh script.

. ./set-envvars.sh
Tip

You must run the script as source or the shorthand ".".


???+ note "Content Library" By default, the machine image artifacts are transferred to a vSphere Content Library as an OVF template and the temporary machine image is destroyed. 1

If an item of the same name exists in the target content library, Packer will update the
existing item with the new version of OVF template.

  1. The Microsoft Windows 11 machine image uses a virtual trusted platform module (vTPM). Refer to the VMware vSphere product documentation for requirements and pre-requisites. The Microsoft Windows 11 machine image is not transferred to the content library by default. It is not supported to clone an encrypted virtual machine to the content library as an OVF Template. You can adjust the common content library settings to use VM Templates.