2011-05-26 45 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