Hi Everyone, Newbie here to the forum and Devops with Packer.
Using Brandon Lee's template for my automated windows server build - PackerBuilds/vmware-WindowsServer2022 at main · brandonleegit/PackerBuilds template. I was able successfully validate but ran into an issue during the packer build process. I need to add a static ip address. Since it static, I am guessing this should be added to the windbuild.json or should this be in the variables.json?
Here is the error I got below:
PS C:\Packer> packer build -var-file .\variables.json .\win19build.json
vsphere-iso: output will be in this color.
==> vsphere-iso: Creating virtual machine...
==> vsphere-iso: Customizing hardware...
==> vsphere-iso: Mounting ISO images...
==> vsphere-iso: Adding configuration parameters...
==> vsphere-iso: Creating floppy disk...
vsphere-iso: Copying files flatly from floppy_files
vsphere-iso: Copying file: SetUp/win19/autounattend.xml
vsphere-iso: Copying file: SetUp/setup.ps1
vsphere-iso: Copying file: SetUp/vmtools.cmd
vsphere-iso: Done copying files from floppy_files
vsphere-iso: Collecting paths from floppy_dirs
vsphere-iso: Resulting paths from floppy_dirs : []
vsphere-iso: Done copying paths from floppy_dirs
vsphere-iso: Copying files from floppy_content
vsphere-iso: Done copying files from floppy_content
==> vsphere-iso: Uploading floppy image...
==> vsphere-iso: Adding generated floppy image...
==> vsphere-iso: Setting temporary boot order...
==> vsphere-iso: Powering on virtual machine...
==> vsphere-iso: Waiting for IP...
==> vsphere-iso: timeout waiting for IP address
==> vsphere-iso: Clearing boot order...
==> vsphere-iso: Powering off virtual machine...
==> vsphere-iso: Deleting floppy image...
==> vsphere-iso: Destroying VM...
vsphere-iso: Closing sessions ....
Build 'vsphere-iso' errored after 32 minutes 12 seconds: timeout waiting for IP address
==> Wait completed after 32 minutes 12 seconds
==> Some builds didn't complete successfully and had errors:
--> vsphere-iso: timeout waiting for IP address
==> Builds finished but no artifacts were created.
Is this the correct format to add the "Network_interface"
{
"builders": [
{
"CPUs": "{{user `cpu_num`}}",
"RAM": "{{user `mem_size`}}",
"RAM_reserve_all": true,
"cluster": "{{user `vsphere_compute_cluster`}}",
"communicator": "winrm",
"convert_to_template": "true",
"datacenter": "{{user `vsphere_dc_name`}}",
"datastore": "{{user `vsphere_datastore`}}",
"disk_controller_type": "lsilogic-sas",
"firmware": "bios",
"floppy_files": [
"SetUp/win19/autounattend.xml",
"SetUp/setup.ps1",
"SetUp/vmtools.cmd"
],
"folder": "{{user `vsphere_folder`}}",
"guest_os_type": "windows2019srvNext_64Guest",
"host": "{{user `vsphere_host`}}",
"insecure_connection": "true",
"iso_paths": [
"{{user `os_iso_path`}}",
"{{user `vmtools_iso_path`}}"
],
"network_adapters": [
{
"network": "{{user `vsphere_portgroup_name`}}",
"network_card": "vmxnet3"
}
],
"network_interface": [
{
"ipv4_address": "ADD IP Address",
"ipv4_netmask": "24",
"ipv4_gateway": "ADD GW Address",
"dns_server_list": "ADD DNS Server ip address"
}
],
"password": "{{user `vsphere_password`}}",
"storage": [
{
"disk_size": "{{user `disk_size`}}",
"disk_thin_provisioned": true
}
],
"type": "vsphere-iso",
"username": "{{user `vsphere_user`}}",
"vcenter_server": "{{user `vsphere_server`}}",
"vm_name": "{{user `vsphere_template_name`}}",
"winrm_password": "{{user `winadmin_password`}}",
"winrm_username": "Administrator"
}
Hey @henryc. Great questions. It looks like you may be using the old template version. Actually I need to look and see if I have updated the packer builds repo there. Which OS are you installing, is it Windows Server 2019 or 2022?
Packer has moved from the JSON format which is the older format to a newer HCL extension and language for Packer to help consolidate on their syntax I believe with Terraform, etc. Let me take a look at the latest template I have locally and see what needs to be pushed up to the repo.
Also, do you have DHCP running in the network? This would be the easiest way to get the machine provisioned and converted to a template.
Also, to answer your question in the comment on the blog post, Packer will automatically convert the new build to a virtual machine template once the process completes.
Let me know if these tidbits make sense. Thanks Henry.
@henryc It looks like with Windows, we can do this with the autounattend.xml file. You would use the following to set a static IP address for your windows build. Just replace with the IP you want to use in the "networking" section.
<Networking> <Interfaces> <Interface wcm:action="add" wcm:keyValue="1"> <Ipv4Settings> <IpAddress>192.168.1.100</IpAddress> <SubnetMask>255.255.255.0</SubnetMask> <Gateway>192.168.1.1</Gateway> <DnsServers> <DnsServer>8.8.8.8</DnsServer> <DnsServer>8.8.4.4</DnsServer> </DnsServers> </Ipv4Settings> </Interface> </Interfaces> </Networking>
Since we are already calling the autounattend file in the build, we should be good to just add the static config and be good to go.
Hey @henryc I am not sure what happened with my last message, think it disappeared maybe due to the long code pasting I did for unattend file. Let me know if you saw it though. I will update the GitHub repo with static address config.