简体   繁体   English

安装gem时Chef崩溃

[英]Chef crashes when installing gem

Im using chef and vagrant as provisioner. 我正在使用厨师和无业游民作为准备者。

When I try to install gems as follows, the app crashes: 当我尝试按以下方式安装gems时,应用程序崩溃:

metadata.rb metadata.rb

gem 'faraday'
gem 'json'

default.rb default.rb

require 'faraday'
require 'json'

conn = Faraday.new(:url => 'http://127.0.0.1:8200')

This error raises: 该错误引发:

==> default: Running handlers:
==> default: [2017-10-25T09:42:43+00:00] ERROR: Running exception handlers
==> default: Running handlers complete
==> default: [2017-10-25T09:42:43+00:00] ERROR: Exception handlers complete
==> default: Chef Client failed. 0 resources updated in 19 seconds
==> default: [2017-10-25T09:42:43+00:00] INFO: Sending resource update report (run-id: 7f4593f5-1c86-409c-95fe-988f09501740)
==> default: [2017-10-25T09:42:43+00:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
==> default: [2017-10-25T09:42:43+00:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report
==> default: [2017-10-25T09:42:43+00:00] ERROR: Expected process to exit with [0], but received '5'
==> default: ---- Begin output of bundle install ----
==> default: STDOUT: Don't run Bundler as root. Bundler can ask for sudo if it is needed, and
==> default: installing your bundle as root will break this application for all non-root
==> default: users on this machine.
==> default: Fetching gem metadata from https://rubygems.org/
==> default: Fetching version metadata from https://rubygems.org/
==> default: Resolving dependencies...
==> default: Installing multipart-post 2.0.0
==> default: Installing json 2.1.0 with native extensions
==> default:
==> default: Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
==> default:
==> default:     current directory: /opt/chef/embedded/lib/ruby/gems/2.3.0/gems/json-2.1.0/ext/json/ext/generator
==> default: /opt/chef/embedded/bin/ruby -r ./siteconf20171025-3434-1qh8whd.rb extconf.rb
==> default: creating Makefile
==> default:
==> default: current directory: /opt/chef/embedded/lib/ruby/gems/2.3.0/gems/json-2.1.0/ext/json/ext/generator
==> default: make "DESTDIR=" clean
==> default:
==> default: current directory: /opt/chef/embedded/lib/ruby/gems/2.3.0/gems/json-2.1.0/ext/json/ext/generator
==> default: make "DESTDIR="
==> default: compiling generator.c
==> default: make: gcc: Command not found
==> default: make: *** [generator.o] Error 127
==> default:
==> default: make failed, exit code 2
==> default:
==> default: Gem files will remain installed in /opt/chef/embedded/lib/ruby/gems/2.3.0/gems/json-2.1.0 for inspection.
==> default: Results logged to /opt/chef/embedded/lib/ruby/gems/2.3.0/extensions/x86_64-linux/2.3.0/json-2.1.0/gem_make.out
==> default: Using bundler 1.12.5
==> default: Installing faraday 0.13.1
==> default: An error occurred while installing json (2.1.0), and Bundler cannot continue.
==> default: Make sure that `gem install json -v '2.1.0'` succeeds before bundling.
==> default: STDERR:
==> default: ---- End output of bundle install ----
==> default: Ran bundle install returned 5
==> default: [2017-10-25T09:42:43+00:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)
Chef never successfully completed! Any errors should be visible in the
output above. Please fix your recipes so that they properly complete.

It seems that gcc is missing, but I can't install it because it tries first to install gems and then executes the recipe, so it crashes before I can do anything. 似乎缺少gcc,但我无法安装它,因为它首先尝试安装gems,然后执行配方,所以它崩溃了,我无法执行任何操作。

-- EDIT -- -编辑-

I've added these lines and is working: 我添加了以下几行,并且正在工作:

metadata.rb: (Remove gem dependency from here) metadata.rb :(从此处删除gem依赖项)

depends 'hashicorp-vault', '~> 2.5.0'
depends 'build-essential', '~> 8.0.3'

default.rb: default.rb:

include_recipe 'hashicorp-vault::default'
chef_gem 'faraday'
chef_gem 'json'
require 'faraday'
require 'json'

安装gcc的Chef-y方法是使用build-essential手册。

Add a shell provisioner before the chef provisioning? 在厨师配置之前添加外壳配置器?

In your Vagrantfile for example: 例如,在您的Vagrantfile中:

Vagrant.configure("2") do |config|
    config.vm.provision :shell, inline: 'yum install -y gcc'
    config.vm.provision :chef, inline: '...'
end

Recipes are perfectly capable of running arbitrary commands, so if you know how to do it manually you can do it with Chef in a pinch. 食谱完全可以运行任意命令,因此,如果您知道如何手动执行,则可以在短时间内使用Chef进行操作。 That being said you should guard any arbitrary commands so they aren't run every single time the recipe runs, only when they're needed. 话虽这么说,您应该警惕任何任意命令,以使它们不会在每次配方运行时都仅在需要时运行。

execute 'sudo yum groupinstall \'Development Tools\'' unless <your logic for 
detecting gcc goes here>

Chef also has Ohai which gathers metadata about the run before it even starts, including what OS you're operating on, so you can make your recipe multiplatform by leveraging that. Chef还拥有Ohai,Ohai甚至在运行之前就收集了有关运行的元数据,包括您正在运行的操作系统,因此您可以利用它使配方成为多平台。

https://docs.chef.io/dsl_recipe.html https://docs.chef.io/dsl_recipe.html

include_recipe 'mycookbook::debian' if node['platform_family'] == 'debian'
include_recipe 'mycookbook::rhel' if node['platform_family'] == 'rhel'

Or, to give you more flexibility if you plan on having many platform types 或者,如果您打算使用多种平台类型,则可以给您更大的灵活性

possible_platforms = ['debian', 'rhel']
if possible_platforms.contains? node['platform_family']
   include_recipe "mycookbook::node['platform_family']"
else
    puts 'This platform isn't valid'
end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM