2011-05-26 46 views
18

我有一個現有的chef-solo項目,我試圖添加vagrant支持。我通常使用knife在EC2服務器上使用Canonical公佈的Ubuntu 10.04 AMI來烹飪這些食譜。Vagrant需要屬性roles.json中打破現有廚師項目

流浪要求我加chef_typejson_class屬性,我的工作roles/*.json文件,像這樣:

{ 
    "name": "memcached", 
    "chef_type": "role", 
    "json_class": "Chef::Role", 
    "run_list": ["base", "memcached"] 
} 

如果我這些添加到角色定義文件,然後我得到這個下一個錯誤。據推測,這些屬性告訴廚師將我的JSON文件視爲Chef :: Role類的實例。

[default] [Thu, 26 May 2011 02:19:44 +0200] DEBUG: NoMethodError: undefined method `run_list_for' for {"name"=>"memcached", "run_list"=>["wantsa", "memcached"]}:Hash 
/opt/ruby/lib/ruby/gems/1.8/gems/chef-0.10.0/bin/../lib/chef/run_list/run_list_expansion.rb:139:in `expand_run_list_items' 
/opt/ruby/lib/ruby/gems/1.8/gems/chef-0.10.0/bin/../lib/chef/run_list/run_list_expansion.rb:78:in `expand' 
/opt/ruby/lib/ruby/gems/1.8/gems/chef-0.10.0/bin/../lib/chef/run_list.rb:138:in `expand' 
/opt/ruby/lib/ruby/gems/1.8/gems/chef-0.10.0/bin/../lib/chef/node.rb:437:in `expand!' 
/opt/ruby/lib/ruby/gems/1.8/gems/chef-0.10.0/bin/../lib/chef/client.rb:249:in `build_node' 
/opt/ruby/lib/ruby/gems/1.8/gems/chef-0.10.0/bin/../lib/chef/client.rb:151:in `run' 
/opt/ruby/lib/ruby/gems/1.8/gems/chef-0.10.0/bin/../lib/chef/application/solo.rb:192:in `run_application' 
/opt/ruby/lib/ruby/gems/1.8/gems/chef-0.10.0/bin/../lib/chef/application/solo.rb:183:in `loop' 
/opt/ruby/lib/ruby/gems/1.8/gems/chef-0.10.0/bin/../lib/chef/application/solo.rb:183:in `run_application' 
/opt/ruby/lib/ruby/gems/1.8/gems/chef-0.10.0/bin/../lib/chef/application.rb:66:in `run' 
/opt/ruby/lib/ruby/gems/1.8/gems/chef-0.10.0/bin/chef-solo:25 
/opt/ruby/bin/chef-solo:19:in `load' 
/opt/ruby/bin/chef-solo:19 

然而,當我嘗試做飯EC2相同角色的chef_typejson_class屬性存在突破的過程中,產生了一個錯誤。這大概是因爲在這種情況下,廚師要像對待一個Ruby散列我的角色定義(並從中調用.delete

/usr/lib/ruby/gems/1.8/gems/chef-0.9.16/bin/../lib/chef/node.rb:379:in `consume_run_list': undefined method `delete' for #<Chef::Role:0x7fa337535138> (NoMethodError) 
    from /usr/lib/ruby/gems/1.8/gems/chef-0.9.16/bin/../lib/chef/node.rb:370:in `consume_attributes' 
    from /usr/lib/ruby/gems/1.8/gems/chef-0.9.16/bin/../lib/chef/node.rb:358:in `consume_external_attrs' 
    from /usr/lib/ruby/gems/1.8/gems/chef-0.9.16/bin/../lib/chef/client.rb:222:in `build_node' 
    from /usr/lib/ruby/gems/1.8/gems/chef-0.9.16/bin/../lib/chef/client.rb:145:in `run' 
    from /usr/lib/ruby/gems/1.8/gems/chef-0.9.16/bin/../lib/chef/application/solo.rb:190:in `run_application' 
    from /usr/lib/ruby/gems/1.8/gems/chef-0.9.16/bin/../lib/chef/application/solo.rb:181:in `loop' 
    from /usr/lib/ruby/gems/1.8/gems/chef-0.9.16/bin/../lib/chef/application/solo.rb:181:in `run_application' 
    from /usr/lib/ruby/gems/1.8/gems/chef-0.9.16/bin/../lib/chef/application.rb:62:in `run' 
    from /usr/lib/ruby/gems/1.8/gems/chef-0.9.16/bin/chef-solo:25 
    from /usr/bin/chef-solo:19:in `load' 
    from /usr/bin/chef-solo:19 
rake aborted! 

當我刪除了chef_typejson_class我的EC2烹飪腳本回去正常工作,但隨後流浪者被打破了。

我在chef-solo命令和Vagrant使用的主要區別在於,我的chef-solo命令與我的roles.json文件有直接關係,而Vagrant's則包含在dna.json文件中。

礦:

ssh [email protected] "cd /etc/chef; sudo env chef_environment=production chef-solo -l info -c config/solo.rb -j roles/memcached.json " 

流浪者之歌:

cd /tmp/vagrant-chef 
chef-solo -c solo.rb -j dna.json 

是否有某種方式,我可以配置我Vagrantfile做這些工作?

回答

1

雖然我沒有遇到這個問題,但我注意到,如果你在不同版本的廚師中使用相同的食譜,作爲移動目標的廚師往往會發生這樣的奇怪事情。

爲了消除這種情況,我會嘗試的第一件事是讓我的廚師版本保持一致。我發現您的Vagrant VM正在使用版本0.10.0,而您的EC2 VM正在使用0.9.16--無論哪個更重要,也許您可​​以在其中進行標準化 - 例如如果您試圖在本地複製您的EC2系統,您可以重新創建您的Vagrant基本框(或者考慮製作您自己的,Vagrant網站上的文檔非常好),以便它與您安裝的內容更加接近EC2。

0

這應該在最新版本的Chef中修復。存在允許無限對象反序列化的JSON漏洞。我相信修復問題也會解決您在這裏看到的問題。

嘗試廚師11和流浪者1.5.6