Overview

The libvirt project:

This Vagrant environment uses libvirt with KVM under Linux.

Required plugins for vagrant provider libvirt

Using libvirt (KVM) requires the Vagrant plugin vagrant-libvirt.

vagrant plugin install vagrant-libvirt

Some boxes have been configured to work with VirtualBox only. With the plugin vagrant-mutate you can convert the images from one VM provider to another. Install the plugin as follows:

vagrant plugin install vagrant-mutate

Now you can download a VirtualBox image and convert it to the libvirt format:

vagrant box add ubuntu/trusty64
vagrant mutate ubuntu/trusty64 libvirt

Save all virtual machines

Because the libvirt provider does not support snapshots like the VirtualBox provider, you must use other tools for taking snapshots. In the following examples the command-line tool virsh from libvirt is used to create and restore snapshots, see Virsh Command Reference for details.

Take a snapshot from all virtual machines:

for vm in $(virsh list --all --name)
do
  virsh snapshot-create-as $vm --name initial-setup
done

Note

Here initial-setup is the name for this snapshot. The snapshot list can be printed with:

for vm in $(virsh list --all --name); do echo $vm; virsh snapshot-list $vm; done

Save a single machine

If only a single machine is to be saved, eg. el6-node1, the following command can be executed:

virsh snapshot-create-as ansible-development_el6-node1 --name initial-setup

Attention

libvirt uses the local directory name, for example ansible-development as a prefix for each virtual machine, see

virsh list --all

Restore all machines

You can restore the saved state for all machines with:

for vm in $(virsh list --all --name)
do
  echo reset $vm
  virsh snapshot-revert $vm --snapshotname initial-setup --running
done

Restore a single machine

If you want to reset the virtual machine el6-node1 to the snapshot initial-setup, enter the following command.

virsh snapshot-revert ansible-development_el6-node1 --snapshotname initial-setup --running

Delete the hole Vagrant environment

If you have done your work then the next command stops the running machines which Vagrant is managing and destroys all resources that were created during the creation process. After running this command, your computer should be left at a clean state, as if you never created the guest machines in the first place.

vagrant destroy -f

Delete a single machine

The removal of a single machine is again shown using the example of el6-node1:

vagrant destroy el6-node1 -f