ENV:PACKER_HTTP_ADDR not being set correctly

Hi all,

I’m trying to build a windows10 template onto a vsphere host and move some large files into a temp directory, As WinRM is too slow for this, I’m trying to get the http_directory working but not having much luck.

The http server comes up and is accessible on my host and guest OS, but attempts to utilise the $ENV:PACKER_HTTP_ADDR variable from within the guest returns a APIPA address (169.). I’m not sure where it’s getting this IP address from. If I do a "write host gci $env:packer" I get the following

vsphere-iso: Name                           Value
vsphere-iso: ----                           -----
vsphere-iso: PACKER_BUILD_NAME              vsphere-iso
vsphere-iso: PACKER_BUILDER_TYPE            vsphere-iso
vsphere-iso: PACKER_HTTP_IP                 169.254.11.253
vsphere-iso: PACKER_HTTP_PORT               8283

here are my interface properties

gwmi win32_networkadapterconfiguration -filter "IPEnabled = 'TRUE'"
DHCPEnabled      : True
IPAddress        : {10.0.0.163, fe80::50c9:a739:4ba8:ff20}
DefaultIPGateway : {10.0.0.253}
DNSDomain        : HOME.local
ServiceName      : Netwtw08
Description      : Intel(R) Wireless-AC 9560 160MHz
Index            : 3

DHCPEnabled      : False
IPAddress        : {172.22.32.1, fe80::ecd7:458d:2c4e:e1dc}
DefaultIPGateway :
DNSDomain        :
ServiceName      : VMSNPXYMP
Description      : Hyper-V Virtual Ethernet Adapter
Index            : 16

and

Get-NetAdapter | select name, deviceid, ifindex, interfacedescription
name                         deviceid                               ifIndex interfacedescription
----                         --------                               ------- --------------------
Bluetooth Network Connection {EDBA0366-9418-4D07-8AA4-1C97275D82C7}      23 Bluetooth Device (Personal Area Network)
Ethernet 2                   {ED1B494B-922F-48DB-8507-95B0E27F0697}      22 SonicWALL Virtual NIC
Ethernet 5                   {CF22AB05-9744-4584-A1EF-1F776BA3B389}      19 Cisco AnyConnect Secure Mobility Client Virtual Miniport Adapter for Windows x64
vEthernet (WSL)              {62F403D7-66EC-450D-A058-AF1425774724}      49 Hyper-V Virtual Ethernet Adapter
Wi-Fi                        {52748637-E8D2-4EF0-AF0A-FCA9985FA051}      12 Intel(R) Wireless-AC 9560 160MHz
Ethernet 6                   {38E7C952-5730-46CC-8B59-5DC7B3F728EE}       8 Dell GigabitEthernet

And here’s my JSON.

    {
      "builders": [
        {
          "CPUs": "{{user `vm-cpu-num`}}",
          "CPU_hot_plug": true,
          "RAM": "{{user `vm-mem-size`}}",
          "iso_url": "{{user `iso_url`}}",
          "iso_checksum": "{{user `iso_checksum`}}",
          "RAM_hot_plug": true,
          "RAM_reserve_all": true,
          "host": "{{user `vsphere-host`}}",
          "http_directory": "./packer-vsphere-iso-windows/data/",
          "vm_version": "10",
          "video_ram": "16384",
          "datacenter": "{{user `vsphere-datacenter`}}",
          "communicator": "winrm",
          "convert_to_template": "false",
          "datastore": "{{user `vsphere-datastore`}}",
          "disk_controller_type": "lsilogic-sas",
          "firmware": "bios",
          "floppy_files":[
            "./packer-vsphere-iso-windows/win10.base/autounattend.xml"
          ],
          "floppy_dirs":[
            "./packer-vsphere-iso-windows/scripts"
          ],
          "folder": "{{user `vsphere-folder`}}",
          "guest_os_type": "windows9_64Guest",
          "insecure_connection": "true",
          "iso_paths": [
            "[] /vmimages/tools-isoimages/windows.iso"
          ],
          "network_adapters": [
            {
              "network": "{{user `vsphere-network`}}",
              "network_card": "vmxnet3"
            }
          ],
          "password": "{{user `vsphere-password`}}",
          "storage": [
            {
              "disk_size": "{{user `vm-disk-size`}}",
              "disk_thin_provisioned": false
            }
          ],
          "type": "vsphere-iso",
          "username": "{{user `vsphere-user`}}",
          "vcenter_server": "{{user `vsphere-server`}}",
          "vm_name": "{{user `vm-name`}}",
          "winrm_password": "{{user `winadmin-password`}}",
          "winrm_username": "Administrator"
        }
      ],
      "provisioners": [
        {
          "type": "file",
          "source": "./packer-vsphere-iso-windows/scripts/",
          "destination": "c:\\Temp"
        },
        {
          "type": "powershell",
          "scripts": [
            "./packer-vsphere-iso-windows/scripts/download-data-folder.ps1
          ]
        },
        {
          "type": "powershell",
          "inline": [
            "iwr -uri http://$ENV:PACKER_HTTP_ADDR/Check_MK/check_mk_agent.msi -outfile c:/temp/check_mk/check_mk_agent.msi ",
            "c:/temp/install-checkmk.ps1"
          ]
        },
      ],
      "sensitive-variables": [
        "vsphere_password",
        "winadmin_password"
      ],
      "variables": {
        "vm-cpu-num": "8",
        "vm-disk-size": "40960",
        "vm-mem-size": "8192",
        "vm-name": "Win10-test",
        "vsphere-datacenter": "Home-Lab",
        "vsphere-datastore": "NVME_esxi",
        "vsphere-host": "esxi.home.local",
        "vsphere-folder": "infra",
        "vsphere-network": "VM Network",
        "vsphere-password": "",
        "vsphere-server": "vsphere.home.local",
        "vsphere-user": "vsphere.home.local\\",
        "winadmin-password": "",
        "iso_url": "./packer-vsphere-iso-windows/isos/windows10_ent.iso",
        "iso_checksum": "2B51705E4AF1D2B2D3FE329370A333FD",
        "winrm_timeout": "6h"
      }
    }

Any help would be appreciated

Edit: after a reboot, it now seems to be picking my WSL interface on the 172 network seen above, so the apipa address it was getting before must have been from one of the other interfaces that was not active
if i break while the provisioner is running and check the packer-ps-env-vars.ps1 it shows;

cat C:\Windows\Temp\packer-ps-env-vars-5f6341e7-d0d7-b303-d15a-531e95ab11a3.ps1
$env:PACKER_BUILDER_TYPE="vsphere-iso"; $env:PACKER_BUILD_NAME="vsphere-iso"; $env:PACKER_HTTP_ADDR="172.22.32.1:8067"; $env:PACKER_HTTP_IP="172.22.32.1"; $env:PACKER_HTTP_PORT="8067";

Not sure how to specify to packer what IP address to use for the var, you’d think because I was able to access 10.0.0.163:8067 (my local IP) from both my guest and host the PACKER_HTTP_ADDR variable should reflect that?

Tried to bind the server to by own address in the builder stage using
"http_bind_address":"10.0.0.163",
to see if that helped but still no dice, still picked up the 172.22.32.1 address.

Bit stumped.

In your logs, you should see a line right before the boot command that says “HTTP server is working at http://” followed by this address. Does the IP not match what you’re seeing?

The the VSphere builder uses to figure out the host IP is here:

if that’s not working, maybe the Packer team needs to investigate a different way of getting it.

Can you open a bug report on the Packer github? This looks like http_bind_address may not be working as desired.