Using Fedora 22 Atomic Vagrant Boxes

One of the new offerings with the Fedora 22 release is a Vagrant box for the Atomic host. While we’re a few months away from the final release, we have an alpha out last week and test candidates for Fedora 22 beta spinning up as we speak. Ready to try out one of the Vagrant boxes? We’ll step through downloading and running the boxes for libvirt/KVM and VirtualBox.

What’s Vagrant?

Virtual machines and containers are fantastic to use to set up development and testing environments, but creating virtual machines manually can be slow and tedious. What we want is a way to spin up an environment quickly, replicate it easily, and dispose of it when we’re done.

Vagrant is a tool that makes it easy to manage a development environment, and even share that configuration with others. Vagrant works with a number of “providers” – such as KVM/libvirt, VirtualBox – and “boxes” that are basically virtual machine base images with a light touch of special sauce.

A lot of folks are already using Vagrant to manage their development environment – if you’re one of those folks, this article may be old news for you. If not, though, read on – you may find Vagrant to be pretty useful.

Getting Images

The alpha images are available via the Cloud pre-release download page. You want to select one of the links for Vagrant Images. If you’re on Fedora 21, you’ll most likely want the libvirt image. If you’re on Windows or Mac OS X, you need the VirtualBox image.

Note that, currently, the images don’t end with the standard “.box” suffix. That should be corrected reasonably soon, but the existing images are perfectly cromulent Vagrant boxes.

You’ll also, of course, need Vagrant installed. If you’re on Mac or Windows, you can find the downloads and installation instructions on the Vagrant site.

Setting Up Vagrant on Fedora 21

Fedora 21 has packaged for Vagrant, so installing Vagrant takes just a few commands. Open a terminal, and run the following:

dnf install -y vagrant-libvirt vagrant

Now, just run “vagrant version” and you should see a message that tells you the version of Vagrant and says “you’re running an up-to-date version of Vagrant!”

Next we’re going to import the box image and start working with it.

Running on Fedora 21 with Vagrant and libvirt

Download the libvirt/KVM image from the Download Fedora Cloud Alpha page. Once it’s downloaded, you can verify the image by checking its checksum against the CHECKSUM file. Use

cd

to change directories to the download directory and use

sha256sum

to verify the image:

sha256sum Fedora-Cloud-Atomic-Vagrant-22_Alpha-20150305.x86_64.rhevm.ova

Assuming it checks out OK, then you’ll want to go ahead and import the box:

vagrant box add f22atomic Fedora-Cloud-Atomic-Vagrant-22_Alpha-20150305.x86_64.rhevm.ova

Now, let’s create a directory where you will create a Vagrantfile, which holds instructions for Vagrant on running the box.

mkdir fed_test
cd fed_test
vagrant init f22atomic

Now, you can pretty much run the box using the stub Vagrantfile without any modifications, but if you want to adjust memory or whatnot you do need to edit it.

Here’s the Vagrantfile I’m using for Fedora 22 Atomic testing:

# Vagrantfile for Fedora 22 Atomic Host

Vagrant.configure(2) do |config|

  config.vm.box = "f22tc2"

  config.vm.provider "libvirt" do |libvirt|
    libvirt.driver = "kvm"
    libvirt.memory = 2048
    libvirt.cpus = 4
  end

end

Let’s walk through that quickly. The first line is just a comment. Vagrant will ignore that and start with the line starting with

Vagrant.configure

. This tells Vagrant that the configuration is starting.

The next line tells Vagrant what box to use. We should have that in the stub Vagrantfile you created with

vagrant init

already, because you passed the boxname to it as an argument.

The next few lines specify that Vagrant should use the libvirt provider, and send a few parameters about the VM. Specifically the amount of memory (2GB) and how many virtual CPUs to use. You can adjust these to taste/the system you’re using. For example, you might want to tweak

libvirt.cpus

to 1 or 2 depending on the host system you’re using.

The default for CPUs is 1 if not set, and the default for memory is 512MB.

Starting Your Vagrant Box

Let’s fire up the Vagrant box and take it for a spin!

vagrant up

Now you’ll see a bunch of text indicating that

vagrant

is starting the machine. It shouldn’t take too long, depending on the speed of your machine.

Once it’s finished, you can log in:

vagrant ssh

That will log you in as the “vagrant” user. Now you’re logged into your virtual environment and can work normally, just

exit

when you’re done. The system will continue running. You can log in again with

vagrant ssh

or you can turn it off with

vagrant halt

.

What if you want to connect to your Vagrant box from a separate machine? You can get the SSH configuration by running the

ssh-config

command:

vagrant ssh-config

This will give you a configuration and location of the private key to use if you want to copy them to another host.

Done with the environment? If you want to get rid of the virtual machine, use the

destroy

command:

vagrant destroy

The

destroy

command will not remove the base box from your system. It will only remove the new environment you’ve created from the Vagrant box. You can also create multiple environments from the same box.

Running on Mac OS X with Vagrant and VirtualBox

If you’re using Mac OS X or Windows, you’ll need a different provider for Vagrant – and VirtualBox seems to be the hands-down most popular option for those platforms.

You’ll need to install Vagrant and VirtualBox from the upstream packages for Mac OS X. Note that with more recent versions of Mac OS X you will need to go to System Preferences -> Security & Privacy -> General and make changes to Allow apps downloaded from: if you’re installing Vagrant and VirtualBox. It’s probably best to stick to Mac App Store and identified developers.

Commands on Mac OS X are pretty much the same as Linux, though you’ll notice two commands available for Vagrant on Mac OS X that are missing from the default Fedora packages:

connect

and

share

. That’s a bit out of scope for this article, but you can use that to share Vagrant boxes to allow people to connect via HTTP/HTTPS or SSH.

Managing Boxes

We’ve run through most of the Vagrant commands you’ll use day-to-day. A couple of additional commands you should be aware of, though, for basic management.

To see all boxes on a machine, use

vagrant box list

. If you need to get rid of a box (not just the most recent environment) use

vagrant box remove foo

where

foo

is the name of the box you’d like to get rid of.

To see the status of all Vagrant boxes, use

vagrant global-status

. The

vagrant status

command will show you the status of the current environment.

Have questions?

If you run into problems with the Atomic boxes, please ask on cloud@lists.fedoraproject.org. We want to provide rock-solid Vagrant boxes for the Fedora Atomic host in Fedora 22, so your feedback will help a lot!

Using Software

3 Comments

  1. Soham

    1) Trying with vagrant-1.7.2, I downloaded the libvirt f22 atomic image and after doing vagrant init f22atomic, I tried to do vagrant up.

    First error was,

    VirtualBox is complaining that the kernel module is not loaded. Please
    run `VBoxManage –version` or open the VirtualBox GUI to see the error
    message which should contain instructions on how to fix this error.

    2) Tried with vagrant up –provider=libvirt

    The provider ‘libvirt’ could not be found, but was requested to
    back the machine ‘default’. Please use a provider that exists.

    3) Did export VAGRANT_DEFAULT_PROVIDER=libvirt

    Same as 2

    4) vagrant plugin install vagrant-libvirt following https://github.com/pradels/vagrant-libvirt. Got,

    An error occurred while installing ruby-libvirt (0.5.2), and Bundler cannot continue.
    Make sure that `gem install ruby-libvirt -v ‘0.5.2’` succeeds before bundling.

    Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

    5) sudo yum install ruby-libvirt and installed ruby-libvirt-0.5.2-3.fc20.x86_64 and ruby-libs-2.0.0.353-16.fc20.x86_64

    6) Try to do vagrant plugin install vagrant-libvirt again and got

    An error occurred while installing ruby-libvirt (0.5.2), and Bundler cannot continue.
    Make sure that `gem install ruby-libvirt -v ‘0.5.2’` succeeds before bundling.

    Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

    /opt/vagrant/embedded/bin/ruby extconf.rb

    Next steps will be tried.

  2. Michael

    This error kill me
    The provider ‘libvirt’ could not be found, but was requested to
    back the machine ‘default’. Please use a provider that exists.

    • Michael

      Actually in some case my error was fixed. Also I found some mistake in text:
      >> vagrant box add f22atomic Fedora-Cloud-Atomic-Vagrant-22_Alpha-20150305.x86_64.rhevm.ova
      We adds box “f22atomic”, but in Vagrantfile it named in other way:
      config.vm.box = “f22tc2”

      But should be f22atomic

Comments are Closed

The opinions expressed on this website are those of each author, not of the author's employer or of Red Hat. Fedora Magazine aspires to publish all content under a Creative Commons license but may not be able to do so in all cases. You are responsible for ensuring that you have the necessary permission to reuse any work on this site. The Fedora logo is a trademark of Red Hat, Inc. Terms and Conditions