Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PACKER_HTTP_ADDR variable not being set correctly #9973

Closed
DarrenF-G opened this issue Sep 21, 2020 · 9 comments
Closed

PACKER_HTTP_ADDR variable not being set correctly #9973

DarrenF-G opened this issue Sep 21, 2020 · 9 comments

Comments

@DarrenF-G
Copy link

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:\Windows\Temp\packer-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

@sylviamoss sylviamoss added bug core Core components of Packer labels Sep 22, 2020
@sylviamoss
Copy link
Member

Thanks for reaching out. We’ll take a look when we get a chance

@hhofs
Copy link

hhofs commented Oct 14, 2020

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

@hhofs
Copy link

hhofs commented Oct 14, 2020

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

@SwampDragons SwampDragons added builder/vsphere and removed core Core components of Packer labels Oct 14, 2020
@SwampDragons SwampDragons added this to the 1.6.5 milestone Oct 14, 2020
@SwampDragons SwampDragons modified the milestones: 1.6.5, 1.6.6 Oct 29, 2020
@redgryphon
Copy link

redgryphon commented Nov 17, 2020

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?

@hhofs
Copy link

hhofs commented Nov 17, 2020

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.

@kkeshavamurthy
Copy link

@redgryphon I'm running into this issue as well. Thanks for working on the PR.

redgryphon added a commit to redgryphon/packer that referenced this issue Jan 18, 2021
@luclis
Copy link

luclis commented Feb 4, 2021

@redgryphon Same issue too. If you need someone for testing your pr, just ask :)

tbennett6421 added a commit to tbennett6421/DetectionLab that referenced this issue Feb 27, 2021
when a packer server has more then one NIC, Packer can often
select the wrong http server using {{ .HTTPIP }}. We extend the
variables file to include an http_server_address which can be set
to the IP address of the correct NIC. This configuration propagates down
to the http_bind_address directive of the builder and the boot_command
entered on the guest VM. Adding 0.0.0.0 as a reasonable default as it
preserves comptability with packers default behavior.

This commit was required to get Packer to build the ubuntu guest
successfully in our environment

Additional Reading:
hashicorp/packer#9973
https://www.packer.io/docs/builders/vmware/vsphere-iso#http-directory-configuration
redgryphon added a commit to redgryphon/packer that referenced this issue Feb 27, 2021
@ghost ghost closed this as completed Apr 15, 2021
@ghost
Copy link

ghost commented Apr 15, 2021

This issue has been automatically migrated to hashicorp/packer-plugin-vsphere#10 because it looks like an issue with that plugin. If you believe this is not an issue with the plugin, please reply to hashicorp/packer-plugin-vsphere#10.

@ghost
Copy link

ghost commented May 16, 2021

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked as resolved and limited conversation to collaborators May 16, 2021
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.