Creating vsphere Templates with Packer, Part 2: Answer Files and Scripts
In this article, we’ll explore the importance of answer files and scripts when creating your vSphere templates. We’ll look at a couple of examples of scripts that can be used to configure your operating system before it is turned into your template. We’ll then move on to answer files that allow automated installation of your operating system without any user prompting.
Let’s get started!
Answer Files:
When creating a vSphere template, you may need to provide configuration details during the operating system installation. This is where answer files come in handy. There are two main types of answer files used in this process; the Windows autounattended.xml and the CentOS kickstart.cfg.
Windows Autounattended.xml:
You can create a windows autounattended.xml using the windows system image manager (Windows SIM). This file contains multiple sections, including disk partition configurations, edition of windows, and even a section to stop the administrator account from expiring. Here is a cut-down example of a Windows answer file:
Key parts of this file are installing VMTools and enabling winrm. VMTools is essential for ensuring that the correct drivers are installed and for getting a network connection, etc. WinRM is necessary to allow packer to continue any post-OS install configurations using PowerShell Provisioner blocks. If winrm isn’t enabled and working, you won’t be able to complete any post-install configuration actions!
Centos Kickstart.cfg:
Like the windows answer file, the centos kickstart.cfg provides configuration details during the operating system installation. Here is an example of a cut-down centos kickstart.cfg file:
This file contains similar sections to the Windows answer file, including local settings and encrypted passwords. There is also a networking section where you can specify that you want the operating system to use DHCP and a packages section where you can specify any packages you want to install during the operating system installation.
Scripts:
Scripts are another essential part of creating your vSphere templates. You may need to make drivers available during the operating system installation, depending on the type of disk controller you plan to use for your templates and subsequent virtual machines. An example of this is drivers for ParaVirtual SCSI (PVSCSI) disk controllers. These drivers aren’t available in Windows by default and need to be provided.
Floppy Files:
When creating your vSphere templates, you may need to make media available during the operating system installation. This could include disk controller drivers or VMware tools. You can use floppy files to achieve this. Here is an example of how to create a floppy file in packer:
In conclusion, answer files and scripts are essential when creating your vSphere templates. They allow automated installation of your operating system without any user prompting and provide configuration details during the installation process. By using answer files and scripts effectively, you can ensure that your virtual machines are configured correctly and ready for use.