Saturday, April 27, 2013

The RightScale plugin for Knife

Ohai!

Here is a brief demo of how one can provision Chef Clients with RightScale using the knife command-line utility.  To do this I will use the knife-rightscale plugin.  At the time of this writing there is just the first beta release available v0.0.2.

This post is intended for chef developers with existing cookbook collateral that want to experiment with  RightScale while leveraging their existing Hosted Chef or Chef Server for client configuration management.

Motivation

More and more the knife utility is becoming an integral part of continuous integration/delivery toolchains.  It is easily invoked from your Jenkins/CI server to provision staging infrastructure on IaaS clouds before running integration/regression tests.  There is already a wide array of cloud plugins to provision servers (e.g. ec2, rackspace, etc.), but leveraging RightScale for provisioning you also get many services/features that you don't need to create or maintain yourself (like monitoring, auto-scaling, and usage reporting just to name a few) -- so you can focus on deploying your company's services.

Requirements

In this demo, I will be using Hosted Chef for my Chef Server -- because I don't want to manage one myself and would rather let the experts do that.  If you don't already have one you can sign up for a free trial of Hosted Chef from Opscode here.

Likewise, you will need a RightScale account with at least one cloud registered.  You can
sign up for a free trial account here.

If you want to following along with this demo, you might also want to take a look at the source so you can cut-and-paste the commands from the README.

Installation

On your local development machine, be sure you are running the latest version Chef 10. Versions earlier than 0.10.0 don't support plugins.   You can install the Chef that I tested with using:

    gem install chef -v 10.24.0

I have not yet tested with Chef 11, but feel free to try!  Now we need to install the plugin. To install it, simply run:

    gem install knife-rightscale

Depending on your system's configuration, you may need to run this command with
root privileges.

Provisioning a Chef Client

As mentioned in the requirements, you will need at least one cloud registered in your RightScale account.  If you only have an EC2 account please see "the fine print" section below, since you will need a feature enabled in your account.

Once the gem is installed, I can list the clouds available in my account:


Okay, most folks wont have this many to choose from, but I work at RightScale and we haz all the clouds.  For this demo, I will randomly choose the "HP Cloud".

Now I need to find my "Chef Client" ServerTemplate.  A ServerTemplate is analogous to a versioned Chef role associated with specific cloud images (among other stuff) that the role has been tested with.  To find the "Chef Client" ServerTemplate I use the following command:



The --name option finds all ServerTemplates with names that contain the string "Chef Client".  I am going to use the latest revision of the v13.4 client template, which is at Revision 4.


NOTE: If you are following along with your own account, the command above wont find anything the first time.  You will need to first import it into your RightScale account -- get it here.  After that the command should find it.

Now that we have identified our cloud and ServerTemplate we can create a new server with the following command:


Notice I pass in the ServerTemplate ID and not the name -- this is to be specific about which version of the template I want.  I also pass in the cloud name, the deployment, and the name I want for the server "CP:ChefClient".  I also specify some inputs for the ServerTemplate including the node name "MyChefClient" and comma separated list of roles (although I just specify one -- "hello_world").  The validation_name and validation_pem inputs reference I am using "cred:" type inputs.  You can just paste your key material on the command-line, but I suggest you login to your RightScale dashboard and create these credential objects to hold your validation secrets.

Here is the output I see as I wait for the server to be ready...


During this time the server is provisioned, RightScale bootstraps you chef client and performs it's first converge.  Once the cloud gives the instance it's network the info is displayed.


Now we can SSH in...


And tail the chef log...


Or view the server in the RightScale dashboard:

When you are done with the server just delete it:


The fine print

I was lazy and only added support for the RightScale API 1.5 (since API 1.0 is EC2 only and being deprecated).  As such, this plugin cannot currently provision servers on EC2.  If you need this capability and would like to take part in a private beta to enable that functionality, please contact support@rightscale.com and they will hook you up.  If you have any problems, please send me an email directly.


1 comment:

Blogger said...

Bluehost is ultimately the best website hosting company with plans for all of your hosting needs.