DanThiffault / rails-lastmile

Chef rails configuration
MIT License
28 stars 23 forks source link

works in vagrant with chef-solo but not when I use chef-server/client #9

Open lvnilesh opened 11 years ago

lvnilesh commented 11 years ago

This is the error I get when I edit Vagrantfile trying to get it working with chef-server

vagrant provision            
[vagrant] Updating host entry for default VM. Administrator privileges will be required...
Password:
[default] Running provisioner: Vagrant::Provisioners::ChefClient...
[default] Creating folder to hold client key...
[default] Uploading chef client validation key...
[default] Generating chef JSON and uploading...
[default] Running chef-client...
stdin: is not a tty
[2013-02-17T02:52:34+00:00] INFO: *** Chef 10.14.2 ***
[2013-02-17T02:52:35+00:00] INFO: Setting the run_list to ["recipe[rails-lastmile]"] from JSON
[2013-02-17T02:52:35+00:00] INFO: Run List is [recipe[rails-lastmile]]
[2013-02-17T02:52:35+00:00] INFO: Run List expands to [rails-lastmile]
[2013-02-17T02:52:35+00:00] INFO: Starting Chef Run for precise64
[2013-02-17T02:52:35+00:00] INFO: Running start handlers
[2013-02-17T02:52:35+00:00] INFO: Start handlers complete.
[2013-02-17T02:52:35+00:00] INFO: Loading cookbooks [rails-lastmile]

================================================================================
Recipe Compile Error in /srv/chef/file_store/cookbooks/rails-lastmile/recipes/default.rb
================================================================================

NameError
---------
uninitialized constant Chef::RubyBuild

Cookbook Trace:
---------------
  /srv/chef/file_store/cookbooks/rails-lastmile/recipes/default.rb:11:in `from_file'

Relevant File Content:
----------------------
/srv/chef/file_store/cookbooks/rails-lastmile/recipes/default.rb:

  1:  #
  2:  # Cookbook Name:: rails-bootstrap
  3:  # Recipe:: default
  4:  #
  5:  # Copyright 2012, 119 Labs LLC
  6:  #
  7:  # All rights reserved - Do Not Redistribute
  8:  #
  9:  class Chef::Recipe

[2013-02-17T02:52:35+00:00] ERROR: Running exception handlers
[2013-02-17T02:52:35+00:00] FATAL: Saving node information to /srv/chef/file_store/failed-run-data.json
[2013-02-17T02:52:35+00:00] ERROR: Exception handlers complete
[2013-02-17T02:52:35+00:00] FATAL: Stacktrace dumped to /srv/chef/file_store/chef-stacktrace.out
[2013-02-17T02:52:35+00:00] FATAL: NameError: uninitialized constant Chef::RubyBuild
The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!

chef-client -c /tmp/vagrant-chef-1/client.rb -j /tmp/vagrant-chef-1/dna.json

My Vagrantfile edits trying to get it work with a chef-server

config.vm.provision :chef_client do |chef|
    chef.chef_server_url = "http://chefserver.cloudapp.net:4000"
    chef.validation_key_path = "~/.chef/validation.pem"
    chef.validation_client_name = "chef-validator"
    chef.add_recipe "rails-lastmile"
    chef.json = {
      'rails-lastmile' => {
        'app_dir' => '/home/vagrant/proj-name',
        'ruby_version' => '1.9.3-p385'
      }
    }
end

I uploaded all needed cookbooks.

knife cookbook list
apt               1.9.0
build-essential   1.3.4
nginx             1.3.0
ohai              1.1.8
rails-lastmile    0.1.0
rbenv             0.7.1
ruby_build        0.6.2
runit             1.0.4
unicorn           1.2.0

My working chef-solo segment

config.vm.provision :chef_solo do |chef|
  chef.cookbooks_path = ["cookbooks","cookbooks-src"]
  chef.add_recipe "rails-lastmile"
  chef.json = {
     'rails-lastmile' => {  
       'app_dir' => '/home/vagrant/proj-name',
       'ruby_version' => '1.9.3-p385'
  } 
}
end

Any ideas where I am going wrong?

lvnilesh commented 11 years ago

It worked when I added these lines to the chef-client segment in Vagrantfile.

I wonder if there is a more elegant way.

    chef.add_recipe "apt"
    chef.add_recipe "build-essential"
    chef.add_recipe "rbenv"
    chef.add_recipe "ruby_build"
    chef.add_recipe "nginx"
    chef.add_recipe "unicorn"
    chef.add_recipe "runit"
    chef.add_recipe "ohai"
DanThiffault commented 11 years ago

I'm not so familiar with Chef Server, but I'm digging in. If you remove the following two lines does it still work?

chef.add_recipe "runit"
chef.add_recipe "ohai"
smeyfroi commented 11 years ago

I think I got the same thing and found that I need at least:

chef.add_recipe "apt"
chef.add_recipe "build-essential"
chef.add_recipe "rbenv"
chef.add_recipe "ruby_build"
lvnilesh commented 11 years ago

Here are my findings:

uninitialized constant Chef::RubyBuild

@DanThiffault it may be a good idea to update README to include these 4 @smeyfroi suggested in run_list before using rails-lastmile.

I am also experimenting with adding capistrano style deployment directory layout as @claco suggests in his asesome blog posts at http://chrislaco.com/devops-toolbox

smeyfroi commented 11 years ago

@lvnilesh I don't know if this is useful, but I definitely need those 4 when I'm building an EC2 instance using https://github.com/nrako/librarian-ec2 (chef-solo, not chef-server).

So in my case I don't need those 4 recipes to build a local vagrant/virtualbox, but I do when using librarian-ec2 to build an EC2 instance.

Not entirely sure why that might be the case, but anyway it does work on an EC2 with those recipes added into the mix. :-)

jbianquetti commented 11 years ago

Just a note: I must add chef.add_recipe "nginx" to Vagrantfile in addition to @smeyfroi recipes...