Packer VMware image with no DHCP

Hi,

This is for Windows image creating.
We are trying to build VMWare image using packer,our environment doesn’t have DHCP server.Winrm is getting a wrong ip address 169...*.My question is there a way I cna specify static ip address for my image build.

==> vsphere-iso: IP address: 169.254.97.161
==> vsphere-iso: Using winrm communicator to connect: 169.254.97.161
==> vsphere-iso: Waiting for WinRM to become available…

2021/04/23 11:49:06 packer-builder-vsphere-iso plugin: [ERROR] connection error: unknown error Post "http://169.254.97.161:5985/wsman": dial tcp 169.254.97.161:5985: connect: connection refused
2021/04/23 11:49:06 packer-builder-vsphere-iso plugin: [ERROR] WinRM connection err: unknown error Post "http://169.254.97.161:5985/wsman": dial tcp 169.254.97.161:5985: connect: connection refused
2021/04/23 11:49:11 packer-builder-vsphere-iso plugin: [INFO] Attempting WinRM connection…
2021/04/23 11:49:11 packer-builder-vsphere-iso plugin: [DEBUG] connecting to remote shell using WinRM
2021/04/23 11:49:11 packer-builder-vsphere-iso plugin: [ERROR] connection error: unknown error Post "http://169.254.97.161:5985/wsman": dial tcp 169.254.97.161:5985: connect: connection refused
2021/04/23 11:49:11 packer-builder-vsphere-iso plugin: [ERROR] WinRM connection err: unknown error Post "http://169.254.97.161:5985/wsman": dial tcp 169.254.97.161:5985: connect: connection refused
2021/04/23 11:49:16 packer-builder-vsphere-iso plugin: [INFO] Attempting WinRM connection…
2021/04/23 11:49:16 packer-builder-vsphere-iso plugin: [DEBUG] connecting to remote shell using WinRM
2021/04/23 11:49:16 packer-builder-vsphere-iso plugin: [ERROR] connection error: unknown error Post "http://169.254.97.161:5985/wsman": dial tcp 169.254.97.161:5985: connect: connection refused
2021/04/23 11:49:16 packer-builder-vsphere-iso plugin: [ERROR] WinRM connection err: unknown error Post "http://169.254.97.161:5985/wsman": dial tcp 169.254.97.161:5985: connect: connection refused

I am trying to set the static IP too because there is no DHCP on the network. Have you figured out a way to set a static IP?

I have similar issue, no DHCP environment I am setting up static ips as part of the FirstLogoncommand via autounattened.xml, problem is packer picks up the 169* ip even before the ip is set, any workarounds appreciated.

Hi
You’re on the right track.

  1. First of all, set static IP in your autounattend.xml file, here’s a great example how Ipv4Settings | Microsoft Learn

  2. Then, add a powershell script to your Packer build (upload in floppy or cdrom files if possible). This one should be loaded into A: or E: drive for instance (depends if you choose floppy/cdrom)

The powershell script will enable winRM at the end of your customization (enable the service, configure http/https listener etc…), something like this is great PowerShell Gallery | scripts/Windows/aws/enable-winrm.ps1 1.0.167

Be careful about port 5986, sometimes it may fail if you’re working with WORKGROUP instead of domain :slight_smile: so you can easily change it for 5985 (http) if your security guidelines allow it. (I prefer to use 5985 to make it work in an isolated VLAN rather than 5986 that fails too much if misconfigured)

  1. Call for script execution into your autounattend.xml into the FirstLogonCommands parameter, here’s how : FirstLogonCommands | Microsoft Learn

Be careful, sometimes it wait for manually logon first (or if you can, just go for autologon)

So to resume :
Packer launch your template with autounattend.xml and load your ps1 script into A:/E: drive > at the end of the installation FirstLogonCommands launch winRM enable/config script > after all, Packer succeed to connect to WinRM then your template is done.

Cheers :slight_smile:
Gael

1 Like