How to Add Static I...
 
Notifications
Clear all

How to Add Static IP address in variables.json file and winbuild.json for Windows Server Packer Build

12 Posts
2 Users
1 Reactions
1,274 Views
Posts: 5
Topic starter
(@henryc)
Active Member
Joined: 4 weeks ago

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.

11 Replies
Posts: 5
Topic starter
(@henryc)
Active Member
Joined: 4 weeks ago

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"
}

Reply
Brandon Lee
Posts: 398
Admin
(@brandon-lee)
Member
Joined: 14 years ago

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.

Reply
6 Replies
(@henryc)
Joined: 4 weeks ago

Active Member
Posts: 5

@brandon-lee I am installing Windows Server 2019 standard. Please let me know when you uploaded the latest template into the repo. Thank you again for your help and guidance.

Reply
Brandon Lee
Admin
(@brandon-lee)
Joined: 14 years ago

Member
Posts: 398

@henryc hey I have pushed up some changes. You should be able to re-pull or git fetch to get the changes down. I have split out the Windows Server 2022 folder into "HCL build" which is the newer format, and then another folder for legacy JSON build.

Reply
Brandon Lee
Admin
(@brandon-lee)
Joined: 14 years ago

Member
Posts: 398

Also, @henryc I made the changes in a hurry so hopefully didn't miss anything. The packer validate ran fine before pushing the changes. But do let me know.

Reply
(@henryc)
Joined: 4 weeks ago

Active Member
Posts: 5

@brandon-lee Thank you, for your WindowsServer2022.json.pkr.hcl file within the line 62 to 65. Is it possible set the static ipv4 address that includes Server ip, gateway and DNS ip? Having DHCP to auto assign an IP address is not a good option for us, since we vmware cluster with other teams that will build servers as well and dont want those servers to accidentally take the template ip by mistake. Here is the section i was referring to below:

network_adapters {
network = "${var.vsphere_portgroup_name}"
network_card = "vmxnet3"
}

Reply
(@henryc)
Joined: 4 weeks ago

Active Member
Posts: 5
Brandon Lee
Admin
(@brandon-lee)
Joined: 14 years ago

Member
Posts: 398

@henryc this should be doable. I will work this in the lab and update you. 👍

Reply
Brandon Lee
Posts: 398
Admin
(@brandon-lee)
Member
Joined: 14 years ago

@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.

Reply
Brandon Lee
Posts: 398
Admin
(@brandon-lee)
Member
Joined: 14 years ago

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.

Reply
Page 1 / 2