I’m just starting out wtih Chef, and I’ve been playing with rather simple
scenarios using chef-server+EC2 and chef-solo/chef-server + Vagrant. So far
it has been awesome, and being able to document and configurate server(s)
in an idempotent way is simply a huge paradigm shift, for the better.
Now, I could be considered someone who doesn’t need to use Chef, since I
don’t deal with a lot of servers right now. In fact, I only have one EC2
slice for now, since most of my websites are Refinery CMS, static among a
few small Rails 3 apps. I don’t need to scale to more servers right now,
one is enough for multiple apps, and Chef is very useful in this scenario
as well, in order to have the server spec and being able to have an exact
copy locally with Vagrant, is priceless.
However, it looks like the multiple vhosts per server scenario is not a
popular one for Chef (and I guess because most of the heavy users probably
use one server per app), so it’s really hard to find clear information on
Let’s say I have a local Vagrant VM running Ubuntu:
This VM will be provisioned and configured by Chef (solo or server) with
nginx, runit and a directory layout like this:
for the apps/websites. Also the Vagrant shared dir on my workstation
would be ~/projects/; a dir where I keep all the code for my projects. This
would be mapped to /srv/ in the VM.
Let’s say I have the VM ready. In my workstation, I would then create a
new project, say, Rails-based, in ~/projects/mynewapp
I would then setup a virtualhost on my local machine, mynewapp.local,
mapping to 127.0.0.1.
Now, I’d like to use Chef to provision the nginx virtualhost for this app
to the VM, and (optionally) deploy the code.
I’ve seen how to do that in the following article:
It’s a very good walkthrough, and although he sets up a LAMP instead of a
nginx/Ruby stack, it’s not hard to translate to using the nginx and Ruby.
However, let’s say next week I create two new Ruby apps. And then 3 static
websites. The amount of Chef recipes would scale pretty quickly and code
duplication as well, I’m afraid.
What I’d like to do is to have a cookbook for setting up the nginx/Ruby
stack VM; another one for Ruby/Rails apps, and another one for static
websites (say, jekyll blogs or simple static html sites directly served by
nginx), and have them be shared by several applications, in a way that I
wouldn’t need to duplicate them for each and every application/site I
When one of those apps are deployed, Chef would check the state of the VM,
and if it’s already setup, it would add the necessary vhost to nginx (if
needed as well), and then deploy the code.
How would I go doing that with chef? If someone could enlighten me, I’d be
Thanks in advance,