我正在将 Chef 与 Vagrant 一起使用,并希望使用 RVM 构建一个 rails 堆栈。
到目前为止,这是我的 Vagrantfile 配置的片段:
...
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
启动 vagrant,配置工作,直到它尝试安装乘客,然后我得到这个错误:
...
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 进入 vagrant,我可以看到 RVM 和 gems 安装得很好:
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)
手动运行rvmsudo passenger-install-apache2-module
效果很好
所以我很确定问题是厨师在没有加载 rvm 的情况下运行它的命令
这里是 cookbooks/passenger_apache2/recipes/default.rb 的命令:第 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
我用于 RVM 和 passaenger_apache 的食谱是:
我尝试用passenger-install-apache2-module --auto
没有rvmsudo passenger-install-apache2-module --auto
运气的替换...
有人知道如何让 rvm 和 rvmsudo 在厨师中工作吗?