[英]How can I set up a dependency to a Ruby library which doesn't exist at the time Chef loads recipes?
設想:
在 recipe1/recipes/default.rb 中:
.. do work
node[:recipe1][:filePath] = ".." #path to file
在 recipe2/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 庫?
使用 Gem package,您在資源上調用 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
( require 'rubygems'
可能不是絕對必要的,因為它應該已經由 Chef 加載,但我們想確定)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.