Лупайте сю скалу...

Іван Франко

 RSS | Atom

19 June 2015


Selected projects See all »

Banalize: Bash static code analyzerDBIx::Report::ExcelShell settings, AKA dotfilesNagios Monitoring for Couchbase serverNagira: RESTful API for NagiosStartpack for Github pages developmentWeb iPhoto

Travel Blog Витрішки »

Україномовний блог Витрішки - блог про все, крім роботи. Цикл статей "Літо на півночі Японії" з цього блогу тепер опублікований у Витрішках

Computer Blog All posts »

iPhoto and files permission Is MacOSX 10.9 == MacOS 9.x? Running Chef roles from Capistrano und Capiche Github & Jekyll: Speeding up Jekyll siteGithub & Jekyll: More experience with Jekyll and setup changesBuild new hosts with Capistrano and Chef Request Tracker: More about custom CSS for RT4Ruby 2 test drive Nagira v0.2.5 release It's UNIX my dear Watson

Slides See all »

Nagira @TLUG, 2012Rspec and Guard


Ярило Yarylo, Jarilo me @ github me @ CPAN Dmytro (CV)

Build new hosts with Capistrano and Chef

Include Chef recipes into Capistrano deploy script, and create full-blown application servers from scratch in a minutes .

I was using Chef-solo to configure new hosts before they can be used to deploy applications by Capistrano. But Capistrano is not just for the app deployment! .

Call Chef from Capistrano

Capistrano is capable of executing batches of commands in parallel on multiple remote servers, and its only dependency is SSH access. So, why not use this to spawn chef-solo processes on these servers?

So, easy solution is to simply include your Chef-solo repository/scripts as a first step in the Capistrano deployment process. This way each time you do a deployment Chef will take care about configuring your server first. And if your server is not configured, or even just recently built, all necessary components will be magically deployed with simply typing cap deploy.

Capistrano Recipe

Add this simple recipe to capistrano to make sure that Chef solo is started before any other Capistrano tasks:

set_default :chef_solo_path, File.expand_path("../chef-solo/", File.dirname(__FILE__))
set_default :chef_solo_json, "empty.json"

namespace :chefsolo do
  task :deploy do
    temp = %x{ mktemp /tmp/captemp-tar.XXXX }.chomp

    run_locally "cd #{chef_solo_path} && tar cfz #{temp} . "
    upload( temp, temp, :via => :scp)
    run_locally "rm -f #{temp}"

    run "mkdir -p ~/chef && cd ~/chef && tar xfz #{temp} && rm -f #{temp}"
    run "#{try_sudo} cd ~/chef && bash ./install.sh #{chef_solo_json}"
  before "deploy", "chefsolo:deploy"

Just make sure that your chef-solo repository is installed in the ./deploy/chef-solo directory or set :chef_solo_path attribute accordingly.

Full text of Chef-solo Capistrano recipe is available in the repository in chef_solo.rb file.

Chef-solo Repository

This is Chef-solo repository that I am using for my deployments. I forked it from somebody else, but heavily modified to suit my needs. Currently install script supports deployment/bootstrapping to MacOSX and several Linux distros. Among supported Linuxes are Debian/Ubuntu and RedHat/CentOS. Wan not tested with Fedora (maybe needs some adjustments for the Rpmforge).

Server Bootsrapping

Even if you do not need to install any additional software using Chef-solo, you still need to put some prerequisits on the server. Like Ruby for Rails development - is an abvious example.

Chef-solo install script can do just that. Without any cookbooks, it would simply create development or production environment by installing: prerequisite development environment (development RPM's or DEB's), Ruby version manager - RVM, Ruby itself and Chef (in that order).

For this simply set :chef_solo_json attribute to "empty.json" as in the example above. "empty.json" is exactly what it says it's an JSON file that does not contain any recipes.

дмитро ковальов
dmytro @ github