5

シナリオ:

  • Recipe1: アーカイブをダウンロードして展開します。Ruby ライブラリも定義する CLI を利用できるようにします。
  • Recipe2: 前述のライブラリの Ruby API を活用します。

レシピ1/recipes/default.rb:

.. do work
node[:recipe1][:filePath] = ".." #path to file

レシピ2/recipes/default.rb:

require node[:recipe1][:filePath]/lib/Library
.. do work

ただし、レシピをロードすると、Chef は次のようにアナウンスします。

[Wed, 17 Aug 2011 19:32:23 +0800] DEBUG: Loading cookbook apache2's definitions from /var/chef/cookbooks/apache2/definitions/web_app.rb
[Wed, 17 Aug 2011 19:32:23 +0800] DEBUG: Loading cookbook apache2's definitions from /var/chef/cookbooks/apache2/definitions/apache_module.rb
[Wed, 17 Aug 2011 19:32:23 +0800] DEBUG: Loading Recipe Recipe1 via include_recipe
[Wed, 17 Aug 2011 19:32:23 +0800] DEBUG: Found recipe default in cookbook Recipe1
[Wed, 17 Aug 2011 19:32:23 +0800] ERROR: Running exception handlers
[Wed, 17 Aug 2011 19:32:23 +0800] ERROR: Exception handlers complete
[Wed, 17 Aug 2011 19:32:23 +0800] DEBUG: Re-raising exception: LoadError - no such file to load -- /path/to/library/Library
/usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require'
/usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `require'
/var/chef/cookbooks/hsltcli/recipes/default.rb:63:in `from_file'
/usr/lib64/ruby/gems/1.8/gems/chef-0.10.4/bin/../lib/chef/cookbook_version.rb:578:in `load_recipe'
/usr/lib64/ruby/gems/1.8/gems/chef-0.10.4/bin/../lib/chef/mixin/language_include_recipe.rb:40:in `include_recipe'
/usr/lib64/ruby/gems/1.8/gems/chef-0.10.4/bin/../lib/chef/mixin/language_include_recipe.rb:27:in `each'
/usr/lib64/ruby/gems/1.8/gems/chef-0.10.4/bin/../lib/chef/mixin/language_include_recipe.rb:27:in `include_recipe'

すべてのレシピが実行中に Ruby ライブラリを宣言/有効化するにはどうすればよいですか?

4

1 に答える 1

4

Gem パッケージを使用して、リソースで run_action() メソッドを呼び出してコンパイル時に実行し、Gem パスがクリアされていることを確認します。例えば:

r = gem_package "dynect_rest" do
  action :nothing
end
r.run_action(:install)
require 'rubygems'
Gem.clear_paths

または、もう少しコンパクトに:

gem_package "dynect_rest" do
  action :nothing
end.run_action(:install)
require 'rubygems'
Gem.clear_paths

(これはChefによってすでにロードされているはずrequire 'rubygems'なので、おそらく厳密には必要ではありませんが、確認したいです)

于 2011-08-20T05:52:31.753 に答える