Vagrant需要role.json中的属性来破坏现有的Chef项目 [英] Vagrant requires attributes in roles.json that break existing Chef project

查看:53
本文介绍了Vagrant需要role.json中的属性来破坏现有的Chef项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have an existing chef-solo project to which I am trying to add vagrant support. I typically use knife to cook these recipes on EC2 servers using Ubuntu 10.04 AMIs published by Canonical.

流浪汉要求我添加 chef_type json_class 属性分配给我的工作 roles / *。json 文件,例如:

Vagrant requires that I add chef_type and json_class attributes to my working roles/*.json files, like this:

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

如果我将其添加到角色定义文件中,则会收到下一个错误。大概这些属性告诉Chef将我的JSON文件视为Chef :: Role类的实例。

If I don't add these to the role definition file, then I get this next error. Presumably these attributes tell chef to treat my JSON file like an instance of Chef::Role class.

[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_type json_class 属性的存在会破坏该过程,并产生下一个错误。大概是因为在这种情况下,厨师想将我的角色定义视为Ruby哈希(并从中调用 .delete

However, when I try to cook the same role on EC2 the existence of chef_type and json_class attributes break the process, yielding the next error. Presumably this is because in this case chef wants to treat my role definition like a Ruby hash (and call .delete from it)

/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_type json_class 我的EC2烹饪脚本恢复正常工作,但随后Vagrant坏了。

When I remove the chef_type and json_class my EC2 cooking scripts go back to working as normal, but then Vagrant is broken.

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

The main difference that I see between my chef-solo command and the one used by Vagrant is that my chef-solo command has a direct relationship to my roles.json file, while Vagrant's is wrapped up in the dna.json file.

矿井:

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 "

无业游民:

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

是否可以通过某种方式配置我的Vagrantfile以使这些工作正常?

Is there some way that I can configure my Vagrantfile to make these work?

推荐答案

虽然我没有遇到这个特殊的问题,但我有请注意,如果您在不同版本的Chef上使用相同的食谱,Chef作为移动目标往往会发生类似这样的奇怪事情。

While I haven't run into this particular problem, I have noticed that Chef, as a moving target, tends to have strange stuff happen like this if you're using the same recipes on different versions of Chef.

只是为了消除这种情况,我要做的第一件事就是使我的厨师版本保持一致。我发现您的Vagrant VM使用的版本是0.10.0,而EC2 VM使用的版本是0.9.16-两者中较重要的一个,也许您可​​以在该版本上进行标准化-例如如果您想在本地复制EC2系统,则可以重新创建Vagrant基本框(或者考虑自己制作,Vagrant网站上的文档非常好),以使其与您所安装的内容更加匹配EC2。

Just to eliminate that, the first thing I would try is to make my chef versions consistent. I see that your Vagrant VM is using version 0.10.0 and your EC2 VM is using 0.9.16 - whichever is more important, perhaps you could standardize on that one - e.g. if you're trying to replicate your EC2 system locally, you can recreate your Vagrant base box (or look into making your own, the documentation is pretty good on the Vagrant website) such that it more closely matches what you've got installed on EC2.

这篇关于Vagrant需要role.json中的属性来破坏现有的Chef项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆