【问题标题】:RVM Ruby Install Breaks Chef-Client On Bootstrapped NodeRVM Ruby 安装在引导节点上破坏 Chef-Client
【发布时间】:2017-04-15 07:51:08
【问题描述】:

我有一个使用 CHEF 引导的 Red Hat Enterprise Linux Server 6.7 版节点。我已在此节点上成功执行了多个食谱/食谱。现在我需要设置这个节点来运行 Ruby On Rails 应用程序。

我有一本食谱成功::

  1. 安装 RVM
  2. 安装 Ruby v2.2

问题

RVM 安装 Ruby 后,引导节点上的 CHEF-Client 不再工作。无论我尝试运行什么食谱/食谱,我都会得到以下输出::

PS C:\Users\JW031544\workspace\CHEF\chef-repo> knife ssh dh2vrtooldev01 "chef-client -o recipe[MY_COOKBOOK::default]" --manual-list --ssh-user MY_USER --ssh-password "MY_PASS"

dh2vrtooldev01 Ignoring executable-hooks-1.3.2 because its extensions are not built.  Try: gem pristine executable-hooks --version 1.3.2
dh2vrtooldev01 Ignoring gem-wrappers-1.2.7 because its extensions are not built.  Try: gem pristine gem-wrappers --version 1.2.7
dh2vrtooldev01 Ignoring nokogiri-1.6.8.1 because its extensions are not built.  Try: gem pristine nokogiri --version 1.6.8.1
dh2vrtooldev01 /opt/chef/embedded/lib/ruby/site_ruby/2.3.0/rubygems/dependency.rb:308:in `to_specs': Could not find 'addressable' (= 2.4.0) among 45 total gem(s) (Gem::MissingSpecError)
dh2vrtooldev01 Checked in 'GEM_PATH=/usr/local/rvm/gems/ruby-2.2.4:/usr/local/rvm/gems/ruby-2.2.4@global', execute `gem env` for more information
dh2vrtooldev01  from /opt/chef/embedded/lib/ruby/site_ruby/2.3.0/rubygems/dependency.rb:320:in `to_spec'
dh2vrtooldev01  from /opt/chef/embedded/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_gem.rb:65:in `gem'
dh2vrtooldev01  from /usr/bin/chef-client:4:in `<main>'

如果我进入节点并告诉 RVM 删除该版本的 Ruby,那么 CHEF-Client 将再次开始正常工作。


问题

有谁知道为什么 CHEF-Client 在 RVM 安装了一个 Ruby 版本后会突然忘记如何运行?


源代码

(default.rb)

include_recipe 'abl_rails::rvm_install'
include_recipe 'abl_rails::ruby_install'

(rvm_install.rb)

# Install RVM (if it doesn't already exist)
execute 'install_rvm' do
  cwd '/root/'
  command 'curl -sSL https://rvm.io/mpapis.asc | gpg2 --import -; curl -L get.rvm.io | bash -s stable'
  not_if {::File.exists?('/etc/profile.d/rvm.sh')}
end

(ruby_install.rb)

# Install Ruby
bash 'install_ruby' do
  cwd '/root/'
   code <<-EOH
    source /etc/profile.d/rvm.sh;
    rvm install #{node['ruby_version']};
  EOH
  not_if "source /etc/profile.d/rvm.sh; ruby --version | grep #{node['ruby_version']}", :cwd => '/root'
  notifies :run, "bash[set_default_rvm_ruby]", :immediately
end

# Set the default Ruby version in RVM
bash "set_default_rvm_ruby" do
  cwd '/root'
  code <<-EOH
    source /etc/profile.d/rvm.sh;
    rvm use #{node['ruby_version']} --default;
  EOH
  action :run
end

【问题讨论】:

    标签: ruby chef-infra rvm rhel


    【解决方案1】:

    这可能在 chef-client 12.17.x 中得到修复,以便 chef-client 正确地脱离 RVM 环境:

    相关 Chef 错误:

    https://github.com/chef/appbundler/pull/24

    https://github.com/chef/chef/issues/5589

    如果它在 12.17.x 之后仍然存在问题(当 ::Gem.clear_paths 存在于 /opt/chef/bin/chef-client appbundler binstub 中时),那么应该针对 appbundler 解决一个新问题。

    (不过,作为 RVM 用户,我不建议将它用于运行生产服务,但我发现在开发工作站类型的环境中使用它非常好——但 YMMV)。

    【讨论】:

      【解决方案2】:

      rvm 使用自定义函数覆盖 cd 内部函数,这会导致错误。尝试删除 rvm 并使用不同的 ruby​​ 管理器,例如 rbenv

      查看这篇博文了解rvmrbenv 之间的其他区别:http://jonathan-jackson.net/rvm-and-rbenv

      老实说,我之前也遇到过同样的问题(但不是和厨师),阅读了更多关于 rvm 的信息,并认为它不是适合我的工具。我确信一定有办法让 rvm 玩得很好,但我认为这不值得。

      【讨论】:

      • 感谢@augusto 的推荐,我最终卸载了 RVM 并使用了 RBENV。我现在可以安装 Ruby 而不会杀死我的 CHEF 客户端。
      猜你喜欢
      • 2013-08-17
      • 2013-07-01
      • 1970-01-01
      • 2015-05-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多