Vagrant 需要 Roles.json 中的属性来破坏现有的 Chef 项目
我有一个现有的 chef-solo 项目,我正在尝试向其中添加 vagrant 支持。我通常使用 Knife 在使用 Canonical 发布的 Ubuntu 10.04 AMI 的 EC2 服务器上烹饪这些食谱。
Vagrant 要求我将 chef_type
和 json_class
属性添加到我的工作 roles/*.json
文件中,如下所示:
{
"name": "memcached",
"chef_type": "role",
"json_class": "Chef::Role",
"run_list": ["base", "memcached"]
}
If I don' t 将这些添加到角色定义文件中,然后我收到下一个错误。据推测,这些属性告诉 Chef 将我的 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_type 和 json_class 属性的存在会破坏该过程,从而产生下一个错误。 Chef 希望将我的角色定义视为 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_type
和 json_class 时,
我的 EC2 烹饪脚本恢复正常工作,但 Vagrant 损坏了。
我发现 Chef-solo 命令与 Vagrant 使用的命令之间的主要区别在于,我的 Chef-solo 命令与 Roles.json 文件有直接关系,而 Vagrant 的命令则包含在 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 "
Vagrants:
cd /tmp/vagrant-chef
chef-solo -c solo.rb -j dna.json
有什么方法可以配置我的 Vagrantfile 来使这些工作吗?
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.
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"]
}
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
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!
When I remove the chef_type
and json_class
my EC2 cooking scripts go back to working as normal, but then Vagrant is broken.
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.
Mine:
ssh [email protected] "cd /etc/chef; sudo env chef_environment=production chef-solo -l info -c config/solo.rb -j roles/memcached.json "
Vagrants:
cd /tmp/vagrant-chef
chef-solo -c solo.rb -j dna.json
Is there some way that I can configure my Vagrantfile to make these work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
虽然我还没有遇到这个特殊问题,但我注意到,如果您在不同版本的 Chef 上使用相同的食谱,Chef 作为一个移动目标,往往会发生这样奇怪的事情。
为了消除这个问题,我要做的第一件事就是使我的厨师版本保持一致。我发现您的 Vagrant VM 使用的是 0.10.0 版本,而您的 EC2 VM 使用的是 0.9.16 - 以哪个更重要为准,也许您可以对此进行标准化 - 例如,如果您尝试在本地复制 EC2 系统,您可以重新创建你的 Vagrant 基础盒子(或者考虑制作你自己的,Vagrant 网站上的文档非常好),这样它就更接近你在 EC2 上安装的内容。
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.
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.
这应该在最新版本的 Chef 中得到修复。存在允许无限对象反序列化的 JSON 漏洞。我相信修复问题也将解决您在这里看到的问题。
尝试 Chef 11 和 Vagrant 1.5.6
This should be fixed in the latest version of Chef. There was a JSON vulnerability that allowed infinite object deserialization. I believe the fix issues for that will also fix the issue you're seeing here as well.
Try out Chef 11 and Vagrant 1.5.6