Using Vagrant with OpenStack28 September 2015 · Filed in Tutorial
In my earlier post on using Docker Machine with OpenStack, I talked about combining technologies in a “provider/consumer” model. In this post, I’m going to talk about creating this provider/consumer model using a different combination of technologies: OpenStack as the infrastructure provider and Vagrant for consuming that infrastructure.
If you’re unfamiliar with Vagrant, I recommend you first read this introduction to Vagrant (after that you can dig into all the other Vagrant-tagged posts). As I explain in that first post, Vagrant leverages the idea of providers (which enable Vagrant to work with various back-end virtualization platforms/solutions) as well as boxes (which are essentially VM templates). In this particular case, we’re leveraging an OpenStack provider for Vagrant that allows Vagrant to use OpenStack as the back-end virtualization solution. However, since OpenStack already has the equivalent of VM templates (in the form of images), there’s no need to use a Vagrant box. This makes using Vagrant with OpenStack slightly different than your typical Vagrant use case.
Let’s start with reviewing some prerequisites—these are the things you’ll need to do/have done before you can use Vagrant with OpenStack (besides the obvious things like having Vagrant installed).
- You’ll need a working OpenStack installation with at least one Glance image uploaded and ready for use.
- You’ll need a provider network (and associated allocation pool) defined, so that OpenStack is able to allocate floating IP addresses to instances.
- You’ll need to know working OpenStack credentials, like your username, password, tenant (project) name, and authentication URL.
Once you have these prerequisites out of the way, you’re ready to start using Vagrant to drive OpenStack.
Driving OpenStack with Vagrant
Here are the details on using Vagrant with OpenStack.
First, install the OpenStack provider plugin (obviously, this only needs to be done once):
vagrant plugin install vagrant-openstack-provider
Next, create a
Vagrantfile with the right settings. The full list of settings for the OpenStack provider is available from the provider’s GitHub page, but here are a few of the highlights (all these fall under the
os.tenant_nameoptions provide the necessary authentication details to allow Vagrant to authenticate against OpenStack.
- Instance details are supplied through the
os.flavor, and the
- Networking information comes from the
- Finally, logging in to the instance is enabled through two different settings. One of them is
config.vm.provider), and this points to the name of a keypair in OpenStack. The second is under
Vagrant.configureand is the
Here’s a sample snippet from a
Vagrantfile for use with the OpenStack provider:
With the OpenStack provider plugin installed and a properly-configured
Vagrantfile in place, then it’s a simple matter of running
vagrant up. Vagrant will authenticate against OpenStack, spin up an instance using the specified image and flavor, allocate a floating IP address, apply the listed security groups, and inject the specified SSH key. How’s that for handy?
Equally handy, when you’re done with the instance(s) created by Vagrant, a simple
vagrant destroy will clean it all up. No need to log into the OpenStack dashboard—just a simple, quick CLI command and you’re done.
Why Vagrant with OpenStack?
As I did in the post on Docker Machine with OpenStack, I want to take a brief moment to talk about why I think this particular combination could be useful. Aside from creating a clean “provider/consumer” relationship between infrastructure being orchestrated by OpenStack and resources being consumed by users via Vagrant, this enables users to apply the same model of consuming resources locally (via Vagrant’s CLI commands) to consuming resources from a cloud implementation (using the same Vagrant CLI commands). In my opinion, anything that makes it easier and simpler for users to consume OpenStack resources is a good thing.
I tested this combination using the following software versions:
- The client system was running OS X 10.9.5 with Vagrant 1.7.4.
- I was using version 0.7.0 of the Vagrant OpenStack provider.
- The OpenStack cloud was running the Juno release on Ubuntu 14.04 LTS, KVM hypervisors, and VMware NSX for networking.
As always, feel free to hit me up on Twitter (or drop me an e-mail) if you have any questions or comments.Tags: CLI · OpenStack · Vagrant Previous Post: Using Docker Machine with OpenStack Next Post: Using Docker Machine with Photon TP2