0

I am trying packer builder with provisioner "shell-local". After successful OS installation I am trying to attach second network adapter. But it stuck in this error. Platform Hyper-V. Code looks like:

source "hyperv-iso" "build-debian" {
    boot_command            = ["<wait><wait><wait><esc><wait><wait><wait>", 
    "/install.amd/vmlinuz ",
    "initrd=/install.amd/initrd.gz ", "auto=true ", "interface=eth0 ", 
    "netcfg/disable_dhcp=true ", 
    "netcfg/confirm_static=true ", "netcfg/get_ipaddress=172.29.48.100 ", 
    "netcfg/get_netmask=255.255.255.0 ", 
    "netcfg/get_gateway=172.29.48.1 ", "netcfg/get_nameservers=8.8.8.8 8.8.4.4 ", 
    "netcfg/get_domain=domain ", 
    "netcfg/get_hostname=hostname ", "url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/preseed.cfg ", 
    "vga=788 noprompt quiet --<enter> "]

  boot_wait               = "10s"
  configuration_version   = "${var.hyperv_version}"
  cpus                    = "${var.cpus}"
  disk_block_size         = "${var.hyperv_disk_block_size}"
  disk_size               = "${var.disk_size}"
  memory                  = "${var.memory}"
  generation              = "${var.hyperv_generation}"
  guest_additions_mode    = "disable"
  http_directory          = "${local.http_directory}"
  iso_checksum            = "sha256:e307d0e583b4a8f7e5b436f8413d4707dd4242b70aea61eb08591dc0378522f3"
  iso_url                 = "http://debian.mirror.vu.lt/debian-cd/11.5.0/amd64/iso-cd/debian-11.5.0-amd64-netinst.iso"
  output_directory        = "${var.build_directory}/packer-${local.template}-${var.git_sha}"
  shutdown_command        = "echo 'vagrant' | sudo -S /sbin/halt -h -p"
  ssh_host                = "${var.ip_address_eth0}"
  ssh_keep_alive_interval = "-1s"
  ssh_password            = "vagrant"
  ssh_port                = 22
  ssh_timeout             = "120m"
  ssh_username            = "vagrant"
  headless                = "false"
  switch_name             = "VmNAT"
  vm_name                 = "${local.template}-${var.git_sha}"

}


build {

name = "BUILD: Debian v11.5"

source "hyperv-iso.build-debian" {
}

provisioner "shell-local" {
    
    execute_command = ["powershell.exe", "{{.Vars}} {{.Script}}"]
    env_var_format   = "$env:%s=\"%s\"; "
    tempfile_extension = ".ps1"
    pause_before = "60s"
    inline =["Import-Module Hyper-V", 
            "Stop-VM -Name ${local.template}-${var.git_sha}", 
            "Timeout /T 20", 
            "Add-VMNetworkAdapter -VMName  ${local.template}-${var.git_sha} -SwitchName  ${var.hyperv_switch} -Name Static -DeviceNaming Off", 
            "Start-VM -Name ${local.template}-${var.git_sha}"   

}
}

packer logs enter image description here

Maybe I'm doing something wrong? And someone know how to fix ? Ty for any help

EDITED:

I made some changes and I think its problem with timeout. While provisioned VM are restarted packer after that tries reconnect to VM, but in this time VM still booting and I get errors like. Is that possible that ssh_timeout works only on first boot ?

robotiaga
  • 315
  • 2
  • 11
  • Error indicates you can't pipe commands to SSH. See following : http://stephanco.blogspot.com/2013/05/new-vm-powershell-commandlet-to-easily.html?force_isolation=true – jdweng Dec 05 '22 at 15:36
  • But its provisioner local-shell it should be executed on buil host for this example its windows 10 host – robotiaga Dec 06 '22 at 06:19
  • Then you have to login and run a script on the remote machine. – jdweng Dec 06 '22 at 09:43
  • Its strange, but if I create second privisioner it starts works as expected.. Your answers off topic or u don't understand what u talking. – robotiaga Dec 06 '22 at 09:47
  • Error says : Input redirection is not supported. Prior it says Waiting for SSH to become available. Also says Waiting 10s for boot? Why are you calling a function that runs on BOOT? – jdweng Dec 06 '22 at 10:01
  • I do not get what u wanna to tell me :D its simple builder which installs Debian os , and i said after succesfull build i tried to add provisioner "shell-local" which imports hyper-v module, turn off VM, adds network adapter and then again turns ON VM. Problem was after turning ON vm, i get this error. But when I tried to add second provisioner I was able to build successfully. – robotiaga Dec 06 '22 at 11:13
  • "Input redirection is not supported." error can be ignored by redirecting error 2> /null .. This error not related to packer build.. – robotiaga Dec 06 '22 at 11:15
  • Sending the error message to null does not fix the issue. You are just hiding important symptoms of the issue. Looks like there is an issue making first connection. It may be an IP routing issue. When a machine starts up it advertises its IP address using ARP. It may take time for the ARP to be recognized by other machines. You may want to do ping from another machine while code is running to see when ping starts to work. To see when machine is working you can check ARP table and wait until the IP is seen in the ARP table. Make sure you do not have more than one machine with same IP. – jdweng Dec 06 '22 at 11:22
  • Do you read what i am typing, or i typing unclearly? Everything starts work when i add second provisioner for example : provisioner "shell-local" { pause_before = "1m" inline = ["works"] } if i delete this provisioner and leave only one provisioner , timeout starts occur .. – robotiaga Dec 06 '22 at 11:29
  • seems somewhere need to set timeout before packer boots it second time, but there is no such option in shell-local "pause_after" – robotiaga Dec 06 '22 at 11:34
  • Do you know how a machine registers its IP address on the network? – jdweng Dec 06 '22 at 11:51
  • it's not network problem... – robotiaga Dec 06 '22 at 12:13
  • I think you are wrong. When a machine starts up is must advertise its IP address on the network. It take time for this to occur when a machine starts up. – jdweng Dec 06 '22 at 12:24

0 Answers0