Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vagrant using Ruby 1.9.3 as default

Hey all i am trying to build a vagrant vm. i am using chef-solo for provisioning and chef-rbenv to manage my versions. so in the vagrantfile i specify

config.vm.provision :chef_solo do |chef|
  chef.cookbooks_path = "cookbooks"
  chef.add_recipe "ruby_build"
  chef.add_recipe "rbenv::system"
  chef.add_recipe "rbenv::vagrant"
  ...

  chef.json = { 
    "rbenv" => {
      "rubies" => [ "1.9.3-p327" ],
      "global" => "1.9.3-p327",
      "gems" => {
      "1.9.3-p327" => [
        { "name" => "bundler" }
        ]
      }
    }
  }
end 

so that the default ruby version will be 1.9.3-p327, but it crashes

Error executing action `install` on resource 'rbenv_ruby[1.9.3-p327] (system)'

and if i dont specify the version in the vagrant file(as seen above), and go with the default rbenv that chef builds so that i can install it once i am in the vm. then i get this

vagrant@precise64:/vagrant$ rbenv install 1.9.3-p327
Downloading yaml-0.1.4.tar.gz...
-> http://dqw8nmjcqpjn7.cloudfront.net/36c852831d02cf90508c29852361d01b
Installing yaml-0.1.4...

BUILD FAILED
...

it works when i run sudo rbenv install 1.9.3-p327 but then when running anything i have to prefix it with sudo even ruby -v

vagrant@precise64:~$ ruby -v
ruby 1.8.7 (2012-02-08 patchlevel 358) [x86_64-linux]
vagrant@precise64:~$ sudo ruby -v
ruby 1.9.3p327 (2012-11-10 revision 37606) [x86_64-darwin12.3.0]

how can i get it installed with chef-solo. i have tried all week and cant get it working at all.

like image 623
TheLegend Avatar asked Oct 04 '22 23:10

TheLegend


1 Answers

The json requires you to specify for chef the rbenv location that your installing ruby to. since the recipes call that you install rbenv on a system level and then a user lvl in this case vagrant.

chef.add_recipe "rbenv::system"
chef.add_recipe "rbenv::vagrant"

So i went and changed the json to this:

chef.json = {
  'rbenv' => {
    'user_installs' => [
      {
        'user'    => 'vagrant',
        'rubies'  => ['1.9.3-p327'],
        'global'  => '1.9.3-p327',
        'gems'    => {
          '1.9.3-p327' => [
            { 'name'    => 'bundler' },
            { 'name'    => 'rake' }
          ]
        }
      }
    ]
  }
}

Also the current rbenv cookbook often has bugs so its good to reference the latest taged version of the cookbook in the cheffile.

cookbook 'rbenv', git: 'git://github.com/fnichol/chef-rbenv.git', ref: "v0.7.2"

like so.

like image 100
TheLegend Avatar answered Oct 07 '22 18:10

TheLegend