chef-infra - Chef Windows - 要求 block 失败

标签 chef-infra

我正在像这样在 Windows 上的 Chef Recipe 中安装 aws-sdk gem

chef_gem 'aws-sdk'
require 'aws-sdk'

chef gem 'aws-sdk' 安装成功但在

上抛出错误
require 'aws-sdk'

错误是LoadError - cannot load such file --- aws-sdk。我在做什么。这里错了。这是 Chef 的完整输出

[2015-01-18T05:13:38+00:00] INFO: Running start handlers
[2015-01-18T05:13:38+00:00] INFO: Start handlers complete.
[2015-01-18T05:13:38+00:00] WARN: found a directory attributes in the cookbook path, but it contains no cookbook files. skipping.
[2015-01-18T05:13:38+00:00] WARN: found a directory definitions in the cookbook path, but it contains no cookbook files. skipping.
[2015-01-18T05:13:38+00:00] WARN: found a directory files in the cookbook path, but it contains no cookbook files. skipping.
[2015-01-18T05:13:39+00:00] INFO: Processing chef_gem[aws-sdk] action install (set_up_machine::default line 31)

================================================================================
Recipe Compile Error in C:\Users\Administrator\Desktop\wincookbook\set_up_machine\recipes\default.rb
================================================================================

    LoadError
    ---------
    cannot load such file -- aws-sdk

    Cookbook Trace:
    ---------------
      C:/opscode/chef/embedded/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:54:in `require'
      C:/opscode/chef/embedded/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:54:in `require'
      C:\Users\Administrator\Desktop\wincookbook\set_up_machine\recipes\default.rb:31:in `from_file'
      C:/opscode/chef/embedded/apps/chef/lib/chef/mixin/from_file.rb:30:in `instance_eval'
      C:/opscode/chef/embedded/apps/chef/lib/chef/mixin/from_file.rb:30:in `from_file'
      C:/opscode/chef/embedded/apps/chef/lib/chef/cookbook_version.rb:245:in `load_recipe'
      C:/opscode/chef/embedded/apps/chef/lib/chef/run_context.rb:169:in `load_recipe'
      C:/opscode/chef/embedded/apps/chef/lib/chef/run_context/cookbook_compiler.rb:140:in `block in compile_recipes'
      C:/opscode/chef/embedded/apps/chef/lib/chef/run_context/cookbook_compiler.rb:138:in `each'
      C:/opscode/chef/embedded/apps/chef/lib/chef/run_context/cookbook_compiler.rb:138:in `compile_recipes'
      C:/opscode/chef/embedded/apps/chef/lib/chef/run_context/cookbook_compiler.rb:75:in `compile'
      C:/opscode/chef/embedded/apps/chef/lib/chef/run_context.rb:92:in `load'
      C:/opscode/chef/embedded/apps/chef/lib/chef/policy_builder/expand_node_object.rb:73:in `setup_run_context'
      C:/opscode/chef/embedded/apps/chef/lib/chef/client.rb:235:in `setup_run_context'
      C:/opscode/chef/embedded/apps/chef/lib/chef/client.rb:397:in `run'
      C:/opscode/chef/embedded/apps/chef/lib/chef/application.rb:243:in `run_with_graceful_exit_option'
      C:/opscode/chef/embedded/apps/chef/lib/chef/application.rb:220:in `block in run_chef_client'
      C:/opscode/chef/embedded/apps/chef/lib/chef/local_mode.rb:38:in `with_server_connectivity'
      C:/opscode/chef/embedded/apps/chef/lib/chef/application.rb:201:in `run_chef_client'
      C:/opscode/chef/embedded/apps/chef/lib/chef/application/solo.rb:245:in `block in interval_run_chef_client'
      C:/opscode/chef/embedded/apps/chef/lib/chef/application/solo.rb:234:in `loop'
      C:/opscode/chef/embedded/apps/chef/lib/chef/application/solo.rb:234:in `interval_run_chef_client'
      C:/opscode/chef/embedded/apps/chef/lib/chef/application/solo.rb:224:in `run_application'
      C:/opscode/chef/embedded/apps/chef/lib/chef/application.rb:58:in `run'
      C:/opscode/chef/embedded/apps/chef/bin/chef-solo:25:in `<top (required)>'
      C:/opscode/chef/bin/chef-solo:52:in `load'
      C:/opscode/chef/bin/chef-solo:52:in `<main>'

    Relevant File Content:
    ----------------------
    C:/opscode/chef/embedded/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:

     47:      end
     48:  
     49:      # If there are no unresolved deps, then we can use just try
     50:      # normal require handle loading a gem from the rescue below.
     51:  
     52:      if Gem::Specification.unresolved_deps.empty? then
     53:        RUBYGEMS_ACTIVATION_MONITOR.exit
     54>>       return gem_original_require(path)
     55:      end
     56:  
     57:      # If +path+ is for a gem that has already been loaded, don't
     58:      # bother trying to find it in an unresolved gem, just go straight
     59:      # to normal require.
     60:      #--
     61:      # TODO request access to the C implementation of this to speed up RubyGems
     62:  
     63:      spec = Gem::Specification.stubs.find { |s|

最佳答案

由于系统上的 ruby​​ 冲突,你在这里不走运。

您的 Ruby 2.1 安装可能已经设置了一些指向您的 2.1 安装的环境变量(如 GEM_PATH),因此当 chef 运行并调用它自己的 gem install 目标时gem 被覆盖,但是当你从 Recipe 中需要它时,你在 Chef 嵌入式 ruby​​ 上下文中并且它是自己的路径,这就是它找不到它的原因,对于 irb 测试也是如此。

对于这种情况,我倾向于使用包装器 .cmd 来清空环境并仅设置所需的环境变量(PATH、SSL_CERT_FILE、USERNAME 等)

有时会出现一些失败并重试的方法来确定需要哪个 ENV var,但最后您确定自己使用的是什么。

关于chef-infra - Chef Windows - 要求 block 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28004098/

相关文章:

ruby - Chef 执行非顺序配方

ruby - 如何用vagrant和chef创建虚拟主机

chef-infra - 在 Chef Solo JSON 中使用属性

java - 使用 Vagrant 时为 Chef 预缓存下载

python - 如何将 python LWRP 与 Opsworks/Chef 11 一起使用

chef-infra - 你如何使 Chef 资源成为可选的?

chef-infra - Chef-client 节点名称必须与客户端名称相同吗?

ruby - Chef12 到 Chef13 升级中的路径问题

python - 通过 Chef Recipe 激活 virtualenv 并安装 python 库

amazon-ec2 - 无法使用 FQDN 为 Chef 客户端配置创建节点