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       
vsphere-iso: PACKER_HTTP_PORT               8283

here are my interface properties

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

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


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",
          "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": [
          "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 ",
      "sensitive-variables": [
      "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=""; $env:PACKER_HTTP_IP=""; $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 (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
to see if that helped but still no dice, still picked up the 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.

I’ve had similar issues with vsphere-iso packer build using the wrong IP for the HTTP directory especially when I was on my company’s VPN vs being hardwired. How we solved this, is that we actually have a shell wrapper that calls packer. Within that script, we ask the user for an IP that the HTTP directory should be accessed at (i use ifconfig and look at the 10. IP in the list) Its not the cleanest solution, but ive been using this fix for months.

1 Like

I’m going to have to do this. Does the wrapper pass an argument to the packer exe? I don’t see such a thing.

So there are 2 ways you can accomplish this:

  1. Create a shell script that asks for user input. That script then generate a JSON vars file that gets passed in via the packer build command. It will look something like packer build -var-file extra_vars.json build.json. Also, I believe you can pass in variables directly, also, via -var flag if you only need the HTTP_IP and not any other user input.

  2. The second way (which I am actually doing now), is instead of having a shell wrapper that will call packer build with your var-file, is wrap it in Ansible. Ansible asks for user input and creates the build.json via a jinja template and the HTTP address can be injected into the build file. So, the build command will now just look like packer build build.json

1 Like

The Ansible option sounds like exactly what I was planning. Post it up if you can!