I’m using Chef with Vagrant and would like to build a rails stack with RVM.
Here’s a snippet of my Vagrantfile configuration so far:
...
config.vm.provision :chef_solo do |chef|
chef.cookbooks_path = "cookbooks"
chef.add_recipe "apt"
chef.add_recipe "build-essential"
chef.add_recipe "ntp"
chef.add_recipe "openssl"
chef.add_recipe "apache2"
chef.add_recipe "mysql"
chef.add_recipe "mysql::server"
chef.add_recipe "redis"
chef.add_recipe "git"
chef.add_recipe "rvm::system"
chef.add_recipe "rvm::gem_package"
chef.add_recipe "passenger_apache2"
chef.json = {
:mysql => {
:server_root_password => 'root',
:bind_address => '127.0.0.1'
},
:redis => {
:daemonize => 'yes',
:port => '6379'
},
:rvm => {
:rubies => 'ruby-1.9.3-p194',
:global_gems => [
{:name => 'bundler'},
{:name => 'rake'},
{:name => 'passenger',
:version => '3.0.17'
}
]
},
:passenger => {
:version => '3.0.17'
}
}
end
Firing up vagrant, the provisioning works until it tries to install passenger, then I get this error:
...
ERROR: gem_package[passenger] (passenger_apache2::default line 48) has had an error
ERROR: gem_package[passenger] (/tmp/vagrant-chef-1/chef-solo-1/cookbooks/passenger_apache2/recipes/default.rb:48:in `from_file') had an error:
gem_package[passenger] (passenger_apache2::default line 48) had an error: NoMethodError: undefined method `join' for nil:NilClass
...
sshing into vagrant, I can see that RVM and the gems installed fine:
vagrant@lucid32:~$ rvm list
rvm rubies
=* ruby-1.9.3-p194 [ i686 ]
# => - current
# =* - current && default
# * - default
vagrant@lucid32:~$ gem list
*** LOCAL GEMS ***
bundler (1.2.1)
daemon_controller (1.0.0)
fastthread (1.0.7)
passenger (3.0.17)
rack (1.4.1)
rake (0.9.2.2)
rubygems-bundler (1.1.0)
rvm (1.11.3.5)
And manually running rvmsudo passenger-install-apache2-module works fine
So I’m pretty sure the problem is chef running its commands without rvm loaded
here are the commands for cookbooks/passenger_apache2/recipes/default.rb: line 48-55
...
gem_package "passenger" do
version node[:passenger][:version]
end
execute "passenger_module" do
command 'passenger-install-apache2-module --auto'
creates node[:passenger][:module_path]
end
The cookbooks I’m using for RVM and passaenger_apache, are:
I tried replacing passenger-install-apache2-module --auto with rvmsudo passenger-install-apache2-module --auto with no luck…
Does anybody know how to get rvm and rvmsudo working in chef?
I believe you are correct in thinking that Chef is executing commands without rvm loaded. Perhaps you can use the
rvm_shellcommand from chef-rvm to install passenger. Something like this might work: