首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Vagrant在roles.json中需要破坏现有Chef项目的属性

Vagrant在roles.json中需要破坏现有Chef项目的属性
EN

Stack Overflow用户
提问于 2011-05-26 08:28:55
回答 2查看 2.6K关注 0票数 18

我有一个现有的chef-solo项目,我正试图在其中添加vagrant支持。我通常使用Canonical发布的Ubuntu10.04AMI在EC2服务器上使用刀子来烹调这些食谱。

Vagrant要求我在工作的roles/*.json文件中添加chef_typejson_class属性,如下所示:

代码语言:javascript
复制
{
  "name": "memcached",
  "chef_type": "role",
  "json_class": "Chef::Role",
  "run_list": ["base", "memcached"]
}

如果我没有将它们添加到角色定义文件中,那么我会得到下一个错误。大概这些属性告诉chef将我的JSON文件视为Chef::Role类的实例。

代码语言:javascript
复制
[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属性的存在会中断这个过程,从而产生下一个错误。这大概是因为在本例中,chef希望将我的角色定义视为Ruby hash (并从中调用.delete )

代码语言:javascript
复制
/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烹饪脚本又恢复了正常工作,但随后Vagrant就坏了。

我看到我的chef-solo命令与Vagrant使用的命令之间的主要区别是,我的chef-solo命令与我的roles.json文件有直接关系,而Vagrant的命令包装在dna.json文件中。

我的:

代码语言:javascript
复制
ssh ubuntu@ec2-xxx-xxx-xxx-xxx.us-west-1.compute.amazonaws.com "cd /etc/chef; sudo env chef_environment=production chef-solo -l info -c config/solo.rb -j roles/memcached.json "

流浪汉:

代码语言:javascript
复制
cd /tmp/vagrant-chef
chef-solo -c solo.rb -j dna.json

有没有什么方法可以配置我的Vagrantfile来使这些文件工作?

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6132516

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档