Search code examples
centosvirtualboxpacker

packer with virtualbox - kickstart can't connect to web server


I'm trying to build centos 7/8 vagrant box with packer on virtualbox. Year ago it worked but now I'm getting connection error on kickstart stage.

Packer starts web server for kickstart and centos installer connects to packers's server and get ks.cfg file.

VM has one network interface with NAT network configured (standard virtualbox NAT with ip 10.0.2.15) I can see, that started VM gets IP address from DHCP but it can't connect to kickstart server which runs on host machine (on ip 10.0.2.2). pins don't work as well.

From the other side - I have configured VM with the same NAT network and I'm able to connect to packers's web server on host 10.0.2.2.

Does anybody knows what's going on or have ant glue? What I do wrong?

PS: Virtualbox version 7.0.4 on Linux host

Here is my packer builder configuration:

source "virtualbox-iso" "my-base" {
  vm_name = "my-base"
  keep_registered = false
  skip_export = false
  cpus = 4
  memory = 2048

  guest_os_type = "RedHat_64"
  iso_url = var.iso_url
  iso_checksum = var.iso_checksum

  http_directory = "."
  boot_command = [
    "<up><tab><wait>",
    " ks={{ .HTTPIP }}:{{ .HTTPPort }}/files/ks.cfg<enter>"
  ]

  ssh_username = "root"
  ssh_password = "${var.root_password}"
  ssh_timeout = "30m"

  shutdown_command = "shutdown -P now"
}

Network configuration in ks.cfg:

network --bootproto=dhcp --device=enp0s3 --onboot=on --hostname="my-base"

I've checked connectivity from already configured VM - it works, and from kickstart VM - it doesn't but if I install OS with normal installer - it works


Solution

  • I came across this same issue and it drove me nuts. I came across this: https://github.com/hashicorp/packer/issues/12118

    Basically, you'll need to add this to your packer builder configuration:

    vboxmanage = [["modifyvm", "{{.Name}}", "--nat-localhostreachable1", "on"]]

    It's a workaround for now but is the only answer I could come across anywhere.