2011-08-17 19 views
5

Kịch bản:Làm thế nào tôi có thể thiết lập một phụ thuộc vào một thư viện Ruby mà không tồn tại tại thời điểm Chef tải công thức nấu ăn?

  • Công thức 1: tải xuống lưu trữ, trích xuất chúng. Làm cho có sẵn một CLI cũng định nghĩa một thư viện Ruby.
  • Công thức 2: tận dụng Ruby API từ thư viện nói trên.

Trong recipe1/công thức nấu ăn/default.rb:

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

Trong recipe2/công thức nấu ăn/default.rb:

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

Tuy nhiên, khi tải các công thức nấu ăn, đầu bếp thông báo:

[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' 

Làm cách nào để tôi có thể khai báo/bật thư viện Ruby sau khi tất cả các công thức có trong p rocess chạy?

Trả lời

4

Sử dụng gói Gem, bạn gọi phương thức run_action() trên tài nguyên để nó xảy ra trong thời gian biên dịch và đảm bảo rằng đường dẫn Gem bị xóa. Ví dụ:

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

Hoặc, hơi nhỏ gọn hơn:

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

(các require 'rubygems' có lẽ không thực sự cần thiết, vì nó nên đã được nạp bởi Chef, nhưng chúng tôi muốn chắc chắn)

Các vấn đề liên quan