HashiCorp Vagrant is widely used for virtual machine provisioning. It can be used to quickly spin up VM in your local server to work as a new development environment. I would like to note some tips that I regularly used to make the process of using Vagrant more efficient.
QEMU/KVM is usually the best choice of hypervisor in Linux environment. To make Vagrant use KVM to run VM, you need to install Vagrant Libvirt Provider. The full installation process are listed in the mentioned GitHub link. In shorts, we need to install some ruby-libvirt depencencies and then execute vagrant plugin install command.
Installing dependencies in Debian
apt-get build-dep vagrant ruby-libvirt
apt-get install qemu libvirt-daemon-system libvirt-clients ebtables dnsmasq-base
apt-get install libxslt-dev libxml2-dev libvirt-dev zlib1g-dev ruby-dev
apt-get install libguestfs-tools
And then install Vagrant Libvirt Provider
vagrant plugin install vagrant-libvirt
After finish the installation, we should test that the Libvirt Provider are working as expected. Try to use vagrant up with the following vagrant file to make sure its work
Vagrant.configure("2") do |config|
config.vm.box = "generic/centos8"
config.vm.hostname = "devvm"
config.vm.provider :libvirt do |libvirt|
libvirt.cpus = 1
libvirt.memory = 1024
end
end
Vagrant should provision the new VM using KVM. You can check from virt-manager to see the new VM running as expected.
Note that not all Vagrant box is compatible with Libvirt Provider. You may need to check a list of compatible box from Vagrant box search tool and specified provider “libvirt” to filter only the box that compatible with libvirt.