In my post about Carpet is a re-mix of existing configuration management solutions, I gave you a rough overview of the problems I tried to address with Carpet. In this article, I want to show you how you can set up a complete Ruby on Rails stack with only a few lines of configuration while leveraging the extensibility of plain Capistrano recipes.
Pre-Requisites To Building And Installing The Carpet Gem
To get started with Carpet, you’ll need to install ruby (>= 1.8.6), rubygems and the following gems:
- capistrano >= 2.5.0
- echoe
- rspec
To install e.g the latest capistrano gem simply type gem install capistrano
. Do the same for echoe and rspec.
Download And Install Carpet
Carpet is a Ruby gem which is currently only available on github. Eventually, I’ll make it available as a directly installable gem, but for now, you’ve got to build it yourself. It sounds more complicated than it is though. There are only three simple steps to get it running:
- Go to http://github.com/webops/carpet/tree/master and hit download or, if you’ve git installed, simply type
git clone git://github.com/webops/carpet.git
at your local command prompt. - cd carpet
- sudo rake install
The third step will build the Carpet gem and install it in your system.
Define Your First Server Type
Now it’s time to provision a new server. The easiest way is to download an OpenSolaris 2008.11 ISO image and install it in a VirtualBox VM.
To get started, let’s simply declare your OpenSolaris server as a physical node (as opposed to a zone, which we’ll cover later). The definition below will ensure you have ntp installed and configured on your server and uploads your public ssh keys to your user account to enable password-less login. Here you go:
Add the following code to carpet/Capfile
:
set(:keys, "your_public_ssh_key") set(:application_user, "your_username_on_the_OpenSolaris_box") type :physical_node do adm.enable_ntp("pool.ntp.org") assure :user, application_user, {:keys => keys} end node 'carpet1', :physical_node, { :ipaddress => "ipaddress_of_your_OpenSolaris_box" }
Now, typing cap physical_node
in your carpet directory, will start the magic. Carpet will reach out to your OpenSolaris box (asking you for a password to login, as no keys have been installed yet) and see what it has to do to fulfill your definition. It will check whether you already have ntp with pool.ntp.org setup and, if not, will do so for you. Same goes for your public SSH keys. If they are already there, Carpet will happily pass over this step. But if not, it will install them for you. That’s the basic idea: Your Carpet definitions should be idempotent – you should be able to fire up Carpet at any point in time and let it walk through your servers finding out whether anything has to change. Carpet itself is taking care of that at a lot of points already.
Define Your Web Server As A Virtual Server Running On Your Physical Node
Let’s now enhance our setup by adding a web server running in a zone on your OpenSolaris box. It’s really straightforward.
Go to your Capfile again and add:
type :web do needs :apache_lb end node "web1", :web, { :hosted_on => : carpet1, :ipaddress => "..." }
Notice the :hosted_on
parameter to the web1 node? This parameter tells Carpet to install that node in a zone on the given node (here: carpet1). And that’s all you have to do. Now, a simple cap web1
is all it needs to:
- create a ZFS filesystem for your zone
- create a zone configuration
- configure the network settings of your zone
- install your user in the zone (with your SSH keys)
- install a lot of required packages into your zone
- and execute the apache_lb appliance recipe which installs and configures apache for you
If you want more, try to create additional zones acting as a Ruby on Rails application server (needs :rails_22
), MySQL server (needs :mysql
) and memcached server (needs :memcached
).
Let me know what you think about it either in the comments or tweet me @webops. If you want to read more about Carpet, subscribe to our RSS feed.
Nice tool! It will definitely simplify the work with Joyent Accelerators (which are solaris zones).
There is a small typo – your_public_ssh_key in the first code snippet doesn’t contain an opening quote.
LikeLike
For the “wishlist” I think it would be interesting to layer a webistrano like / go-grid like interface over top of this as well perhaps. Using YUI you should be able to model something up pretty quickly.
Kent Langley
LikeLike
@Kirill: Great that you like it. Thanks for spotting the typo – it’s fixed.
@Kent: yes, for me, 3tera was a kind of a role model for thinking in “appliances”. Such a GUI would be really cool.
LikeLike