Updated June 2016

Got a question on how I setup vagrant-libvirt. This is my most basic setup.

Install Vagrant

Easy enough! Install the deb

wget https://releases.hashicorp.com/vagrant/1.8.4/vagrant_1.8.4_x86_64.deb
sudo dpkg -i vagrant_1.8.4_x86_64.deb

Install libvirt and qemu-kvm

Follow the Ubuntu Libvirt Guide

$ sudo apt-get update
$ sudo apt-get install qemu-kvm libvirt-bin libvirt-dev
$ sudo adduser $USER libvirtd

Install vagrant-libvirt gem

This step may require libvirt-dev deb package be installed.

$ vagrant plugin install vagrant-libvirt
$ vagrant plugin list
vagrant-libvirt (0.0.33)

Install Vagrant Boxes

A Vagrant box is a tar archive with 3 files in it.

  • base VagrantFile
  • metadata.json
  • QCOW2 image

You can also build your own Vagrant box very easily using Packer and Packer build templates found in chef/bento github repo.

Example: using a PC with a Monitor

git clone https://github.com/chef/bento
cd bento
packer build -only qemu ubuntu-14.04.amd64.json
vagrant box add builds/ubuntu-14.04.libvirt.box --name "trusty64"

Example: using a Server with No Monitor Access (headless)

git clone https://github.com/chef/bento
cd bento
packer build -only qemu -var "headless=true" ubuntu-14.04.amd64.json
vagrant box add builds/ubuntu-14.04.libvirt.box --name "trusty64"

Verify the box is installed

$ vagrant box list
trusty64 (libvirt, 0)

Create a 2 VM Vagrant file

Create a 2 VM Vagrant file using libvirt, with their eth1 addresses in a very isolated network config. Basically this is a bridge with no DNSMASQ running or NAT applied. This setup is useful for connecting VM NICs via IP. It is not suitable for L2 config like point to point VM links that need BPDUs or other types of L2 protocols to flow between the VMs. LLDP frames/BPDUs are consumed by the host. eth0 on the VMs is managed by vagrant code and it automatically assigns it to a bridge with DNSMASQ and NAT applied.

Topology

Simple breakdown of libvirt topology
here

Vagrant Configuration

# -- mode: ruby --

vi: set ft=ruby :

Vagrant.configure(2) do |config| # The most common configuration options are documented and commented below. # For a complete reference, please see the online documentation at # https://docs.vagrantup.com.

config.vm.box = "trusty64" # vagrant issues #1673..fixes hang with configurenetworks config.ssh.shell = "bash -c 'BASHENV=/etc/profile exec bash'" config.vm.provider :libvirt do |domain| domain.memory = 256 domain.nested = true end

# testvm1 config.vm.define :testvm1 do |node| node.vm.hostname = 'testvm1' # not a fan of the syncedfolder feature node.vm.syncedfolder '.', '/vagrant', :disabled => true # (testvm1)eth1 === eth1(testvm2) node.vm.network :privatenetwork, :ip => '169.2.2.2/24', # bogus IP so tha vagrant-libvirt can create virtnetwork :autoconfig => false, :libvirtforwardmode => 'veryisolated', :libvirtdhcp_enabled => false, :libvirtnetworkname => 'testnetwork' end

# testvm2 config.vm.define :testvm2 do |node| node.vm.hostname = 'testvm2' # not a fan of the syncedfolder feature node.vm.syncedfolder '.', '/vagrant', :disabled => true

# (testvm2)eth1 === eth1(testvm1)
node.vm.network :private_network,
  :ip => '169.2.2.2/24', # bogus IP so tha vagrant-libvirt can create virt_network
  :auto_config => false,
  :libvirt__forward_mode => 'veryisolated',
  :libvirt__dhcp_enabled => false,
  :libvirt__network_name => 'test_network'

end end