Building a RHEL 9 VM template in vSphere 8 using Packer
This post is a sub topic based on my previous post on using the Packer Examples for vSphere GitHub repository.
https://connectedtech.com.au/ghost/#/editor/post/66c301dfee5f4400014117fc
As part of my interest in optimising and automating the way I build virtual machines for my project use cases, I am looking at using the Red Hat Ansible Automation Platform in my home lab environment. As I starting point, I am going to build a Red Hat Enterprise Linux version 9 VM template to make it easy and quicker to provision a server. I expect to be breaking and making mistakes along my Ansible learning journey so it will be good to save on time rather than building RHEL VMs using the manual DVD iso installation method.
Here are the steps I took to build the template.
Step 1 - Update the rhsm.pkrvars.hcl file
I have created a Red Hat Developer's account to enable me to apply new updates for the RHEL VMs.
// Red Hat Subscription Manager Credentials
rhsm_username = "username"
rhsm_password = "somesecurepassword"
Step 2 - Download the DVD iso file
Ensure the RHEL DVD iso is in the nominated datastore as per the vsphere.pkrvars.hcl file and in the correct location.

Step 3 - Build the template
From the packer examples directory, run the build.sh script.
josephdizon@provision-vm-01:~/provision/packer-examples-for-vsphere$ ./build.sh
From the menu, select 1 for Linux
Packer Examples for vSphere v0.20.0 (Branch: heads/v0.20.0)
B U I L D
Select a guest operating system:
1: Linux
2: Windows
Enter q to quit or i for info.
Select a guest operating system: 1
From the Linux distribution menu, select 6 for Red Hat Enterprise Linux.
Packer Examples for vSphere v0.20.0 (Branch: heads/v0.20.0)
B U I L D
Select a Linux distribution:
1: AlmaLinux OS
2: CentOS
3: Debian
4: Fedora Server
5: Oracle Linux
6: Red Hat Enterprise Linux
7: Rocky Linux
8: SUSE Linux Enterprise Server
9: Ubuntu Server
10: VMware Photon OS
Enter b to go back, or q to quit.
Enter a number of the Linux distribution: 6
From the version menu, select 1 for version 9. Then select c to continue.
Packer Examples for vSphere v0.20.0 (Branch: heads/v0.20.0)
B U I L D
Select a version:
1: Red Hat Enterprise Linux 9
2: Red Hat Enterprise Linux 8
3: Red Hat Enterprise Linux 7
Enter b to go back, or q to quit.
Select a version: 1
Build a Red Hat Enterprise Linux 9 virtual machine image for VMware vSphere?
Warning: The branch name contains a slash ('/') which may cause issues with the build.
Would you like to (c)ontinue, go (b)ack, or (q)uit? c
Two outputs to check to make sure the installation is going well.
- The command line output should show the following,
Initializing HashiCorp Packer and the required plugins...
Starting the build of Red Hat Enterprise Linux 9...
vsphere-iso.linux-rhel: output will be in this color.
==> vsphere-iso.linux-rhel: Creating virtual machine...
==> vsphere-iso.linux-rhel: Customizing hardware...
==> vsphere-iso.linux-rhel: Adding SATA controller...
==> vsphere-iso.linux-rhel: Mounting ISO images...
==> vsphere-iso.linux-rhel: Adding configuration parameters...
==> vsphere-iso.linux-rhel: Starting HTTP server on port 8040
==> vsphere-iso.linux-rhel: Setting boot order...
==> vsphere-iso.linux-rhel: Powering on virtual machine...
==> vsphere-iso.linux-rhel: Waiting 2s for boot...
==> vsphere-iso.linux-rhel: Serving HTTP requests at http://10.8.10.3:8040/.
==> vsphere-iso.linux-rhel: Typing boot command...
==> vsphere-iso.linux-rhel: Waiting for IP...
- A VM should appear in the template folder and show operating system build activities.

The template creation should now be complete.
