【问题标题】:Vagrant requires attributes in roles.json that break existing Chef projectVagrant 需要在 roles.json 中破坏现有 Chef 项目的属性
【发布时间】:2011-09-02 05:10:39
【问题描述】:

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

Vagrant 要求我将 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 烹饪脚本恢复正常工作,但随后 Vagrant 坏了。

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

我的:

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 以使这些工作?

【问题讨论】:

    标签: chef-infra vagrant


    【解决方案1】:

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

    为了消除这种情况,我会尝试的第一件事是让我的厨师版本保持一致。我看到您的 Vagrant 虚拟机使用的是 0.10.0 版本,而您的 EC2 虚拟机使用的是 0.9.16 - 哪个更重要,也许您可​​以对那个版本进行标准化 - 例如如果你想在本地复制你的 EC2 系统,你可以重新创建你的 Vagrant 基本盒子(或者考虑制作你自己的,Vagrant 网站上的文档非常好),以便它更接近你安装的内容EC2。

    【讨论】:

      【解决方案2】:

      这应该在最新版本的 Chef 中得到修复。存在允许无限对象反序列化的 JSON 漏洞。我相信修复问题也将解决您在此处看到的问题。

      试用 Chef 11 和 Vagrant 1.5.6

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-11-22
        • 2011-06-11
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多