virt-install templates? kvm/qemu/libvirt, vagrant, etc.?

Posted by gregorie12@reddit | linuxadmin | View on Reddit | 2 comments

I am looking to create VMs to test Ansible for configuring as much of the VM as possible starting with a minimal install of a Linux distro. For example, for AlmaLinux, it is RHEL-based so I would pass it a Kickstart file to do the init work of e.g. partitioning, setting up network, secure ssh access, etc. (hopefully I can pass an SSH key alongside the Kickstart file for the SSH connection Ansible needs). Then Ansible sets up the rest of the system.

Is kvm/qemu/libvirt and passing virt-install the image the recommended way for this? I've also come across vagrant and distrobox. For the latter, it's not suitable because of limitations with containers. It looks like vagrant kind of a VM version of distrobox?

For virt-install are there public templates available for different "profiles", e.g. "desktop", "headless", "gaming" to pass in appropriate settings like passthrough, networking, graphics, etc. depending on such priorities? There's dozens of settings and there's no practical way to know whether the settings are appropriate for a particular optimization. I have this so far for passthrough, is there anything missing or something that might be unnecessary?

virt-install \
  --name "$hostname" \
  --os-variant "$osinfo" \
  --virt-type kvm \
  --arch x86_64 \
  --cpu host-passthrough \
  --vcpus="$vcpu" \
  --video virtio \
  --graphics spice,listen=none \
  --memory "$memory" \
  --disk path="${img_name},format=qcow2,bus=virtio,cache=writeback" \
  --sound none \
  --channel spicevmc \
  --channel unix,target.type=virtio,target.name=org.qemu.guest_agent.0 \
  --console pty,target.type=virtio \
  --network type=default,model=virtio \
  --controller type=virtio-serial \
  --controller type=usb,model=none \
  --controller type=scsi,model=virtio-scsi \
  --input type=keyboard,bus=virtio \
  --rng /dev/urandom,model=virtio \
  --noautoconsole \
  "$virt_install_arg"

Is it decent enough to use for both a headless VM and a desktop VM usage or should I e.g. remove the graphics part if using for headless?

Much appreciated.