07 12 / 2011

How to manage multiple chef servers chef client?

I was stupid enough on how to manage multiple chef clients for multiple chef servers.


I played with Opscode hosted chef servers. Actually, I was astonished with chef through those guys presentations/talks. And later I installed one local chef-server to play around.

But I was always confused on what are the files do I need to change while switching to the previous or another one. Should I keep them(3 files; client key, organization validator key and knife.rb) in ~/chef or ~/.chef or ~/other_folder/.chef.

But, today I find this approach simple and simple.

Do cd inside any folder that you’re managing for different servers. Make one directory named .chef and put your client key, orgnization validator kye, knife.rb

Now when you run any knife -h commands being inside that folder, the configuration will be read first from the .chef directory.

It made me much simpler, should have known before!!


Permalink 42 notes

04 12 / 2011

rvm install ruby woes!!

Sometime when upgrading RVM or just doing a fresh install and try to install Rubies, one might stumble upon a weird problem. I’ve also encountered such situations several times. Specially, when RVM brings breaking changes while updating. The following is the most recurring issue I’ve faced with. So, just documenting for this time so that I don’t have to Google it again.

rvm install ree
ruby-1.8.7-p330 - #fetching
ruby-1.8.7-p330 - #extracting ruby-1.8.7-p330 to /Users/andrew/.rvm/src/ruby-1.8.7-p330
ruby-1.8.7-p330 - #extracted to /Users/andrew/.rvm/src/ruby-1.8.7-p330
ruby-1.8.7-p330 - #configuring
ruby-1.8.7-p330 - #compiling
Error running 'make ', please read /Users/andrew/.rvm/log/ruby-1.8.7-p330/make.log
There has been an error while running make. Halting the installation.

If you do it again, you’ll see the error

Installing Ruby Enterprise Edition from source to: /Users/millisami/.rvm/rubies/ree-1.8.7-2011.03
It appears that the archive has already been extracted. Skipping extract (use --force to force re-download and extract).
ree-1.8.7-2011.03 - #installing 
ERROR: Error running './installer -a /Users/millisami/.rvm/rubies/ree-1.8.7-2011.03  --no-tcmalloc --dont-install-useful-gems -c --with-readline-dir=/usr/local/Cellar/readline/6.2.1', please read /Users/millisami/.rvm/log/ree-1.8.7-2011.03/install.log
ERROR: There has been an error while trying to run the ree installer. Halting the installation.

When you see the log file, you’ll see something at the end of that file:

readline.c: In function ‘username_completion_proc_call’

This error is due to the readline library.

Now you’ve got 2 options. One is to install readline via rvm pkg install readline or if you have homebrew installed, you can install it via brew update; brew install readline.

Then, brew info readline will show the readline path.

So now, you opt for either way.

# if you go via homebrew way
$ rvm remove ree
$ rvm install ree -C --with-readline-dir=/usr/local/Cellar/readline/6.2.1

# if with rvm way
$ rvm get head; rvm reload
$ rvm pkg install readline
$ rvm remove ree
$ rvm install ree --with-readline-dir=$rvm_path/usr



Permalink 10 notes

02 12 / 2011

Cache sweeper in Rails3.1, if not using ActiveRecord!

If you’re using Rails 3.1 but without ActiveRecord, then you cannot use the the expire_page, expire_action and expire_fragment in your controller. This might happen if you use ODMs such as Mongoid. The app that I’m working on uses Mongoid.

So, the work-around is to add a Mongoid::Observer and expire those caches by creating an instance of the ActionController::Base and call those methods on that object.

class LineObserver < Mongoid::Observer
 observe :line

 def after_save(line)

 def after_destroy(line)

   def expire_cache(line)
     @cont ||= ActionController::Base.new
     @cont.expire_fragment "department_lines" if line.public?

Hope this saves someone’s time.

23 11 / 2011

Build your own Vagrant box ready to use with chef-solo using Veewee

This is my first screencast and its a bit glitchy. The voice is not good because I’d to use the built-in microphone of my MacBook pro. I’ve to get a good one. So bare with me and the audio.

Things to shop


  • You know what is Virtual Box and Vagrant
  • You are familiar with Git and Github
  • You use Bundler and RVM

Building a brand new box using Ubuntu 11.10 32-bit iso image

Visit https://github.com/jedi4ever/veewee and Fork the repo under your account

Git clone git clone git://github.com/millisami/veewee cd veewee

Bundle install (if you don’t have Bundler installed, do gem install bundler --pre)

millisami at sachin in ~/gitcodes/veewee on master
± bundle install                                                                                                                                                                                                 
Fetching gem metadata from http://rubygems.org/.......
Using Platform (0.4.0) 
Using archive-tar-minitar (0.5.2) 
Using bundler (1.1.rc) 
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.
millisami at sachin in ~/gitcodes/veewee on master

Gems required

gem install vagrant
gem install veewee

Define a basebox template

First, lets see what are the templates available.

millisami at sachin in ~/gitcodes/veewee on master
± bundle exec vagrant basebox templates                                                                                                                                                             
The following templates are available:
vagrant basebox define '<boxname>' 'ubuntu-10.10-server-i386-netboot'
vagrant basebox define '<boxname>' 'ubuntu-11.04-server-amd64'
vagrant basebox define '<boxname>' 'ubuntu-11.04-server-i386'

So, the ubuntu 11.10 has not been defined yet. Lets build one based off the ubuntu-11.04-server-i386

millisami at sachin in ~/gitcodes/veewee on master
± bundle exec vagrant basebox define 'milli-ubuntu-11-10-32-bit' 'ubuntu-11.04-server-i386'                                                                                                         
The basebox 'milli-ubuntu-11-10-32-bit' has been successfully created from the template ''ubuntu-11.04-server-i386'
You can now edit the definition files stored in definitions/milli-ubuntu-11-10-32-bit
or build the box with:
vagrant basebox build 'milli-ubuntu-11-10-32-bit'

Lets see the structure of the generated folder

millisami at sachin in ~/gitcodes/veewee on master
± tree definitions                                                                                                                                                                                  
└── milli-ubuntu-11-10-32-bit
    ├── definition.rb
    ├── postinstall.sh
    └── preseed.cfg

1 directory, 3 files

Open up the folder in your editor

Open up the file definition.rb and change the version numbers from 11.04 to 11.10

# definition.rb
  :cpu_count => '1', :memory_size=> '384', 
  :disk_size => '10140', :disk_format => 'VDI', :hostiocache => 'off',
  :os_type_id => 'Ubuntu',
  :iso_file => "ubuntu-11.10-server-i386.iso",
  :iso_src => "http://releases.ubuntu.com/11.10/ubuntu-11.10-server-i386.iso",
  :iso_md5 => "881d188cb1ca5fb18e3d9132275dceda",
  :iso_download_timeout => "1000",
  :boot_wait => "10", :boot_cmd_sequence => [
    '/install/vmlinuz noapic preseed/url=http://%IP%:%PORT%/preseed.cfg ',
    'debian-installer=en_US auto locale=en_US kbd-chooser/method=us ',
    'hostname=%NAME% ',
    'fb=false debconf/frontend=noninteractive ',
    'keyboard-configuration/layout=USA keyboard-configuration/variant=USA console-setup/ask_detect=false ',
    'initrd=/install/initrd.gz -- <Enter>'
  :kickstart_port => "7122", :kickstart_timeout => "10000", :kickstart_file => "preseed.cfg",
  :ssh_login_timeout => "10000", :ssh_user => "vagrant", :ssh_password => "vagrant", :ssh_key => "",
  :ssh_host_port => "7222", :ssh_guest_port => "22",
  :sudo_cmd => "echo '%p'|sudo -S sh '%f'",
  :shutdown_cmd => "shutdown -P now",
  :postinstall_files => [ "postinstall.sh"], :postinstall_timeout => "10000"

Open up the file postinstall.sh and change libreadline5-dev to libreadline5 because the Ubuntu Oneiric doesn’t have libreadline5-dev package.

millisami at sachin in ~/gitcodes/veewee on master
± be vagrant basebox build 'milli-ubuntu-11-10-32-bit'

23 11 / 2011