【问题标题】:Chef-client can't seem to run bundle installChef-client 似乎无法运行 bundle install
【发布时间】:2013-08-29 18:04:26
【问题描述】:

我正在尝试使用 application_ruby cookbook 在 Chef 设置的服务器上部署我的 Rails 应用程序。当 chef-client 到达运行 bundle install 的点时,它崩溃了,说它找不到 bundler。我怀疑这可能与我在此服务器上使用 RVM 的事实有关,但我不确定该怎么做。

这是我的应用配方:

database_name = "app_#{node.chef_environment}"
api_deploy_key = Chef::EncryptedDataBagItem.load('keys', 'app_repository')["deploy_key"]

application "my_app" do
  path "/var/www"
  owner 'ubuntu'
  repository "git@github.com:my_account/app.git"
  revision node.chef_environment == "production" ? "master" : "develop"
  deploy_key api_deploy_key

  rails do
    gems [['Bundler', '1.3.4']]
    database_master_role 'db_master'
    database do
      database database_name
      username "ubuntu"
      password Chef::EncryptedDataBagItem.load('passwords', 'db')["password"]
    end

    bundler true
    precompile_assets true
  end
end

这是它产生的错误:

================================================================================
Error executing action `run` on resource 'execute[bundle install --path=vendor/bundle --deployment --without development test cucumber production]'
================================================================================


Mixlib::ShellOut::ShellCommandFailed
------------------------------------
Expected process to exit with [0], but received '1'
---- Begin output of bundle install --path=vendor/bundle --deployment --without development test cucumber production ----
STDOUT: 
STDERR: /usr/local/rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:296:in `to_specs': Could not find 'bundler' (>= 0) among 175 total gem(s) (Gem::LoadError)
    from /usr/local/rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:307:in `to_spec'
    from /usr/local/rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems/core_ext/kernel_gem.rb:47:in `gem'
    from /usr/local/rvm/gems/ruby-1.9.3-p125@global/bin/bundle:22:in `<main>'
    from /usr/local/rvm/gems/ruby-1.9.3-p125/bin/ruby_noexec_wrapper:14:in `eval'
    from /usr/local/rvm/gems/ruby-1.9.3-p125/bin/ruby_noexec_wrapper:14:in `<main>'
---- End output of bundle install --path=vendor/bundle --deployment --without development test cucumber production ----
Ran bundle install --path=vendor/bundle --deployment --without development test cucumber production returned 1

Resource Declaration:
---------------------
# In /var/chef/cache/cookbooks/application_ruby/providers/rails.rb

 86:     execute "#{bundle_command} install --path=vendor/bundle #{bundler_deployment ? "--deployment " : ""}--without #{common_groups}" do
 87:       cwd new_resource.release_path
 88:       user new_resource.owner
 89:       environment new_resource.environment
 90:     end
 91:   else



Compiled Resource:
------------------
# Declared in /var/chef/cache/cookbooks/application_ruby/providers/rails.rb:86:in `block in class_from_file'

execute("bundle install --path=vendor/bundle --deployment --without development test cucumber production") do
  action "run"
  retries 0
  retry_delay 2
  command "bundle install --path=vendor/bundle --deployment --without development test cucumber production"
  backup 5
  cwd "/var/www/releases/30858f319060ca556b5109aa6d0ac64afa3f8e38"
  environment {"RAILS_ENV"=>"staging", "PATH"=>"/usr/local/rvm/rubies/ruby-1.9.3-p125/bin:/usr/local/rvm/gems/ruby-1.9.3-p125/bin:/usr/local/rvm/gems/ruby-1.9.3-p125@global/bin:/usr/local/rvm/rubies/ruby-1.9.3-p125/bin:/usr/local/rvm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games"}
  returns 0
  user "ubuntu"
  cookbook_name "my_app"
end

如果我将rollback_on_error设置为false,我可以手动进入签出的代码目录,运行bundle install没有问题。

这里出了什么问题,我该如何解决?

【问题讨论】:

  • 手动到签出目录的时候,能不能切换到运行chef的用户(我猜是root)尝试运行bundle install

标签: ruby rvm bundler chef-infra


【解决方案1】:

你的环境设置错了,应该是:

environment {
  "RAILS_ENV"=>"staging", 
  "PATH"=>"/usr/local/rvm/gems/ruby-1.9.3-p125/bin:/usr/local/rvm/gems/ruby-1.9.3-p125@global/bin:/usr/local/rvm/rubies/ruby-1.9.3-p125/bin:/usr/local/rvm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games", 
  "GEM_PATH"=>"/usr/local/rvm/gems/ruby-1.9.3-p125:/usr/local/rvm/gems/ruby-1.9.3-p125@global", 
  "GEM_HOME"=>"/usr/local/rvm/gems/ruby-1.9.3-p125"
}

【讨论】:

  • 谢谢。在配方的rails 块中使用environment 添加GEM_PATHGEM_HOME 似乎已经解决了问题。
  • 另请注意,您的PATH 在开始时有一个额外的/usr/local/rvm/rubies/ruby-1.9.3-p125/bin - 它不应该在那里
猜你喜欢
  • 2011-05-05
  • 2020-02-14
  • 2014-01-28
  • 2016-02-29
  • 2016-08-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多