Packer: PACKER_HTTP_ADDR variable not being set correctly

Created on 21 Sep 2020  路  5Comments  路  Source: hashicorp/packer

Issue;
While trying to use the http_directory directive, packer binds to the correct local interface/address and can be accessed by both Host and guest as expected, however the $env:packer_http_address variable does not get set to the same bind address. It will either get set to an apipa address or pick up an address from a random interface.

Packer: 1.6.2(tried 1.60 with same result)
Builder: vsphere-iso
Host: Wndow 2004 (19041.508)
vCenter: 6.7.0.10000
esxi: 6.7.0, 15018017

Interfaces present - https://gist.github.com/DarrenF-G/8b5c6d010b066bbd79d8460410adb071
Packer log for windows 10 build - https://gist.github.com/DarrenF-G/959bfd8fb7dcb0192d5092d609a4dbba
Packer log for Ubuntu build - https://gist.github.com/DarrenF-G/0b931613860185e43662db2dcaec8f5c
Example json - https://gist.github.com/DarrenF-G/17753bd304235539877c1c423d9cbaad

if I step though the windows post-deployment and and run
cat C:WindowsTemppacker-ps-env-vars-5f6341e7-d0d7-b303-d15a-531e95ab11a3.ps1
I get;
$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";

as no http server is binding on 172.22.32.1 i am unable to pull down files using this variable.
Tried to replicate it on another windows host with only one interface and get the same result, it sets the address as 169.* instead of my local IP.
I also tried an ubuntu image too as it uses http.ip and http.port but it also sets the variables to a 169.* address when it should set it to a 10.* address(see the above logs)

Let me know if you need any further information

bug buildevsphere track-internal

Most helpful comment

Working around it by using an additional variable for the ip address, the HTTP server seems to be responding to requests just fine, it just sets the wrong value

variable "builderip"          {default = "10.103.1.17"}

source "vsphere-iso" "template" {
    boot_wait = "5s"
    boot_command = [
        "<esc><wait>",
        "install <wait>",        
        "preseed/url=http://${var.builderip}:{{ .HTTPPort }}/preseed.cfg <wait>",   # using builderIP variable instead of {{ .HTTPIP }} as it get the wrong value:  https://github.com/hashicorp/packer/issues/9973    
        "debian-installer=en_US.UTF-8 <wait>",
        "auto <wait>",
        "locale=en_US.UTF-8 <wait>",        
        "kbd-chooser/method=us <wait>",
        "keyboard-configuration/xkb-keymap=us <wait>",        
        "netcfg/get_hostname=debian <wait>",
        "netcfg/get_domain=vagrantup.com <wait>",
        "fb=false <wait>",
        "debconf/frontend=noninteractive <wait>",
        "console-setup/ask_detect=false <wait>",
        "console-keymaps-at/keymap=us <wait>",
        "grub-installer/bootdev=/dev/sda <wait>",
        "<enter><wait>"
    ]

All 5 comments

Thanks for reaching out. We鈥檒l take a look when we get a chance

I'm having the same issue on packer 1.6.3, it seems to be selecting the wrong NIC (the one with no cable plugged in)

==> vsphere-iso.template: HTTP server is working at http://169.254.115.102:8551/

image

Working around it by using an additional variable for the ip address, the HTTP server seems to be responding to requests just fine, it just sets the wrong value

variable "builderip"          {default = "10.103.1.17"}

source "vsphere-iso" "template" {
    boot_wait = "5s"
    boot_command = [
        "<esc><wait>",
        "install <wait>",        
        "preseed/url=http://${var.builderip}:{{ .HTTPPort }}/preseed.cfg <wait>",   # using builderIP variable instead of {{ .HTTPIP }} as it get the wrong value:  https://github.com/hashicorp/packer/issues/9973    
        "debian-installer=en_US.UTF-8 <wait>",
        "auto <wait>",
        "locale=en_US.UTF-8 <wait>",        
        "kbd-chooser/method=us <wait>",
        "keyboard-configuration/xkb-keymap=us <wait>",        
        "netcfg/get_hostname=debian <wait>",
        "netcfg/get_domain=vagrantup.com <wait>",
        "fb=false <wait>",
        "debconf/frontend=noninteractive <wait>",
        "console-setup/ask_detect=false <wait>",
        "console-keymaps-at/keymap=us <wait>",
        "grub-installer/bootdev=/dev/sda <wait>",
        "<enter><wait>"
    ]

I think I found by myself this bug. Instead of opening a new issue I'll try to contribute here.

This is my experience. I have a builder machine with 3 different NICs. One of them is connected to my workstation, another to the VMware VCenter network and the last one is exposed to the VM to be packed.
While trying to pack a CentOS 8 machine I noticed that the old floppy way to provide a Kickstart file did not work anymore. I turned then to the web server solution. Enabled with the appropriate option, the web server binded on the correct IP (forced via the http_bind_address option). Packer still picked the wrong NIC. It issued the boot line with the wrong address (the one on the VMware network) and obviously the whole packing process failed.

I noticed that in this comment the code is supposed to put the address used to bind the web server inside the state. There is only a reference to the port, though.

I tried to add a line like this
state.Put("http_ip", s.HTTPAddress)
just after the comment alongside the similar line regarding the port.
I rebuilt packer and everything worked correctly.

Should I propose a PR or will it be addressed by the maintainers?

I would suggest proposing a PR, will make life easier for the maintainers, so the chance of it being fixed in an upcoming version will be higher.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

frezbo picture frezbo  路  3Comments

sourav82 picture sourav82  路  3Comments

DanielBo picture DanielBo  路  3Comments

Tensho picture Tensho  路  3Comments

znerd picture znerd  路  3Comments