thomasklein94 / packer-plugin-libvirt

Packer Plugin for Libvirt
Mozilla Public License 2.0
20 stars 15 forks source link

Packer ignores ssh_host key #53

Closed zimmnik closed 1 year ago

zimmnik commented 1 year ago

Mission: install package from public repo to openwrt-22.03.5-x86-64-generic-ext4-combined-efi.img image.

Conditions: Backed-in root password empty, qemu-agent absent. Image have one preconfigured interface

Problem: Packer ignores ssh_host key and trying to find dynamic IP address via qemu_agent

TIP Bridge interface on host can be quickly created via NetworkManager

nmcli connection add con-name demo ifname br0 type bridge ipv6.method disabled ipv4.method manual ipv4.addresses 192.168.1.2/24

Code:

packer {
  required_plugins {
    libvirt = {
      version = ">= 0.4.3"
      source  = "github.com/thomasklein94/libvirt"
    }
  }
}

source "libvirt" "main" {
  libvirt_uri = "qemu:///system"
  domain_name = "demo"

  vcpu        = "1"
  memory      = "256"

  volume {
    alias = "artifact"
    name  = "demo.img"
    pool  = "default"
    source {
      type = "external"
      urls = ["file://${path.cwd}/artifacts/openwrt-22.03.5-x86-64-generic-ext4-combined-efi.img"]
    }
    format     = "raw"
    target_dev = "vda"
    bus        = "virtio"
  }

  network_interface {
    alias  = "communicator"
    type   = "bridge"
    bridge = "br0"
  }

  communicator {
    communicator = "ssh"
    ssh_host     = "192.168.1.1"
    ssh_username = "root"
    ssh_password = ""
  }
}

build {
  name = "main"
  source "libvirt.main" {}
}
zimmnik commented 1 year ago

I need recheck this issue, because stock openwrt image have only one preconfigured interface updated issue description

thomasklein94 commented 1 year ago

Hi @zimmnik,

I'm a little bit torn over this, as setting up an address manually via ssh_host is prone to user errors, but in the meantime, it shouldn't be silently ignored for sure.

You can find in the plugin's documentation that there is an option to use other methods to obtain the IP address of the VM. In your case, I think you can use the arp method. The benefit of this is packer will wait until there is an IP address present on the interface. The downside is that if there is no communication coming from that interface, there is no way for the host machine to learn the IP-MAC pairing on it's interfaces.

However, After giving it some thoughts, I must acknowledge that there could be a need (like in your case) where explicitly specifying the SSH address is necessary and I will look into a way to support that.

Thank you for bringing up this issue