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.
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.
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.
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:
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!
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:
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
What if you want to connect to your Vagrant box from a separate machine? You can get the SSH configuration by running the
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 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:
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.
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.
If you run into problems with the Atomic boxes, please ask on email@example.com. We want to provide rock-solid Vagrant boxes for the Fedora Atomic host in Fedora 22, so your feedback will help a lot!