简体   繁体   中英

Up-to-date Chef cookbook for ruby

Is there an up-to-date cookbook for ruby? I wasn't able to find one on the opscode cookbook site. ie ruby 1.9.3 or 1.9.2p280.

I just finished updating Carlo Zottman's ruby 1.9.x cookbook (noticed this question while having lunch, prior to writing a pull request, lol...)

The only dependencies are the standard build-essential and apt cookbooks from the opscode cookbook site.

As for the discussion about when a cookbook such as this one might be needed, I'm using it to upgrade from ruby 1.8 to ruby 1.9 on my 12.04.01 vagrant boxes before using the rbenv cookbook (and various others).

I realize that I ought to be able to use the rbenv cookbook to install 1.9.3, but after futzing with that unsuccessfully for a couple of hours, I realized that I was happier with the source installation anyway, as it makes my whole recipe stack less brittle. And a shell script to rbenv install 1.9.3 as the vagrant user was trivial to write.

Update

I found an alternative approach that has even fewer dependencies (yes!) I'm using Fletcher Nichol's cookbooks:

  • ruby_build from the opscode community page
  • chef-rbenv from github (Not the same as the rbenv cookbook at opscode)

Strictly speaking, of course, you could just use ruby_build to install your preferred 1.9 and stop, but I want rbenv as well.

I've included some snippets from my setup (there's more to the Berksfile and Vagrantfile, of course, but these are the relevant bits.) The only truly tricky part is that the local name of the chef-rbenv cookbook has to be rbenv if you want to use any of the off-the-shelf recipes that include other off-the-shelf recipes from the cookbook, as it refers to itself as rbenv. Berkshelf made that trivial.

Berksfile :

group :ruby do
  cookbook 'ruby_build'
  cookbook 'rbenv', git: 'https://github.com/fnichol/chef-rbenv'
end

Vagrantfile:

config.vm.provision :chef_solo do |chef|
  chef.cookbooks_path = 'chef/cookbooks'
  chef.roles_path     = 'chef/roles'
  chef.json           = {
    'rbenv' => {
      'global' => '1.9.3-p194',
      'rubies' => [ '1.9.3-p194' ],
      'gems'   => {
        '1.9.3-p194' => [
          { 'name'   => 'bundler' }
        ]
      }
    }
  }
  chef.add_role 'ruby'
end

chef/roles/ruby.json:

{
  "name": "ruby",
  "description": "Install ruby and rbenv",
  "chef_type": "role",
  "json_class": "Chef::Role",

  "run_list": [
    "recipe[ruby_build]",
    "recipe[rbenv::system]"
  ]
}

A final comment is that once I figured the solution out, I realized that Victor's answer is likely the chef server version of the same thing. I have only used chef-solo so far, so I am not sure.

I'm not sure whether you'll find one for updating the system version of Ruby, as chef is built on top of Ruby, and would therefore be updating itself whilst running, which I'm not sure is possible.

However, I've definitely seen Chef cookbooks for Ruby version managers such as RBenv and RVM, such as this one for rbenv , and this one for RVM . Is this for a Server or an OSX dev box? if it's for the later, then I've found Smeagol to be a pretty handy shortcut when configuring machines.

I think the easiest is to use two cookbooks: ruby_build and rbenv. In your role ( <proj>/roles/role_name.rb ):

name "your-role-name"

description "All the shelves!"

run_list(
  "recipe[ruby_build]",
  "recipe[rbenv::system]"
)

override_attributes(
  'rbenv' => {
    'global' => '1.9.2-p280',
    'rubies' => [
      '1.9.2-p280'
    ]
  }
)

Adding this role (preferably before other roles that would require these rubies) to your run list should do it.

To edit a run list: knife node edit <node name>

Don't forget to update the role! knife role from file role_name.rb

Lastly, rubyenv may be a slightly cleaner way of managing rubies than rvm.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM