Chef官方配方上的语法错误,配置Vagrant

时间:2015-03-04 12:00:15

标签: vagrant chef chef-solo

我在官方食谱上出现语法错误。当我试图从一个流浪盒里面运行这个配方时,它工作正常。我用过:

chef-client --local-mode --runlist [...]

现在我尝试使用chef-solo配置盒子,因为chef-client需要服务器和密钥。它应该是等价的。

这是我的Vagrantfile,我有两台机器,每台都由一些厨师配方提供。我还将ssh设置为X模式,DNS重定向以进行名称解析,分配给每台计算机的内存以及共享文件夹。

如果我添加到运行列表recipe1,recipe2,或者甚至没有运行列表中的任何收件人,则会出现错误。

VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|

  config.vm.box = "hashicorp/precise64"

  # Needs vagrant 1.7.2 or newer
  # chef.install = true
  # chef.version = "latest"

  # ---- BEGIN MOST RELEVANT PART ----
  config.vm.define "mybox" do |a|
    a.vm.network "private_network", ip: "192.168.33.12"
    config.vm.provision "chef_solo" do |chef|
        chef.cookbooks_path = "myproject-cookbook/cookbooks"
        #chef.add_recipe "myproject::recipe1"
        #chef.add_recipe "myproject::recipe2"
        #chef.add_recipe "myproject::recipe3"
    end
  end
  # ---- END MOST RELEVANT PART ----

  config.vm.define "myotherbox" do |c|
    c.vm.network "private_network", ip: "192.168.33.11"
    config.vm.provision "chef_solo" do |chef|
        chef.cookbooks_path = "myproject-cookbook/cookbooks"
        chef.add_recipe "myproject::recipe4"
    end
  end

  config.ssh.forward_x11 = true

  config.vm.provider :virtualbox do |vb|
      # DNS queries to the host, which becomes a DNS Proxy
      vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]

      # Lease more RAM to the guest
      vb.customize ["modifyvm", :id, "--memory", "2048"]
  end
  config.vm.synced_folder "../shared", "/home/vagrant/public"
end

实际的错误来自官方食谱,窗口,如果我还没有指定一个食谱,我不知道为什么厨师会运行它。

$ vagrant provision
==> mybox: Running provisioner: chef_solo...
Generating chef JSON and uploading...
==> mybox: Warning: Chef run list is empty. This may not be what you want.
==> mybox: Running chef-solo...
==> mybox: stdin: is not a tty
==> mybox: [2015-03-04T11:08:09+00:00] INFO: *** Chef 10.14.2 ***
==> mybox: [2015-03-04T11:08:11+00:00] INFO: Run List is []
==> mybox: [2015-03-04T11:08:11+00:00] INFO: Run List expands to []
==> mybox: [2015-03-04T11:08:11+00:00] INFO: Starting Chef Run for precise64
==> mybox: [2015-03-04T11:08:11+00:00] INFO: Running start handlers
==> mybox: [2015-03-04T11:08:11+00:00] INFO: Start handlers complete.
==> mybox: 
==> mybox: ================================================================================
==> mybox: Recipe Compile Error in /tmp/vagrant-chef-1/chef-solo-1/cookbooks/windows/libraries/windows_package.rb
==> mybox: ================================================================================
==> mybox: 
==> mybox: SyntaxError
==> mybox: -----------
==> mybox: /tmp/vagrant-chef-1/chef-solo-1/cookbooks/windows/libraries/windows_package.rb:239: syntax error, unexpected ':', expecting kEND
==> mybox:         provides :windows_package, os: "windows"
==> mybox:                                       ^
==> mybox: Cookbook Trace:
==> mybox: ---------------
==> mybox:   /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/chef-10.14.2/bin/../lib/chef/run_context.rb:140:in `load'
==> mybox:   /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/chef-10.14.2/bin/../lib/chef/run_context.rb:140:in `load_libraries'
==> mybox:   /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/chef-10.14.2/bin/../lib/chef/run_context.rb:230:in `call'
==> mybox:   /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/chef-10.14.2/bin/../lib/chef/run_context.rb:230:in `foreach_cookbook_load_segment'
==> mybox:   /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/chef-10.14.2/bin/../lib/chef/run_context.rb:229:in `each'
==> mybox:   /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/chef-10.14.2/bin/../lib/chef/run_context.rb:229:in `foreach_cookbook_load_segment'
==> mybox:   /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/chef-10.14.2/bin/../lib/chef/run_context.rb:227:in `each'
==> mybox:   /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/chef-10.14.2/bin/../lib/chef/run_context.rb:227:in `foreach_cookbook_load_segment'
==> mybox:   /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/chef-10.14.2/bin/../lib/chef/run_context.rb:137:in `load_libraries'
==> mybox:   /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/chef-10.14.2/bin/../lib/chef/run_context.rb:62:in `load'
==> mybox:   /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/chef-10.14.2/bin/../lib/chef/client.rb:198:in `setup_run_context'
==> mybox:   /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/chef-10.14.2/bin/../lib/chef/client.rb:418:in `do_run'
==> mybox:   /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/chef-10.14.2/bin/../lib/chef/client.rb:176:in `run'
==> mybox:   /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/chef-10.14.2/bin/../lib/chef/application/solo.rb:230:in `run_application'
==> mybox:   /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/chef-10.14.2/bin/../lib/chef/application/solo.rb:218:in `loop'
==> mybox:   /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/chef-10.14.2/bin/../lib/chef/application/solo.rb:218:in `run_application'
==> mybox:   /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/chef-10.14.2/bin/../lib/chef/application.rb:70:in `run'
==> mybox:   /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/chef-10.14.2/bin/chef-solo:25
==> mybox:   /opt/vagrant_ruby/bin/chef-solo:19:in `load'
==> mybox:   /opt/vagrant_ruby/bin/chef-solo:19
==> mybox: 
==> mybox: Relevant File Content:
==> mybox: ----------------------
==> mybox: /opt/vagrant_ruby/lib/ruby/gems/1.8/gems/chef-10.14.2/bin/../lib/chef/run_context.rb:
==> mybox: 
==> mybox:   1:  #
==> mybox:   2:  # Author:: Adam Jacob (<adam@opscode.com>)
==> mybox:   3:  # Author:: Christopher Walters (<cw@opscode.com>)
==> mybox:   4:  # Author:: Tim Hinderliter (<tim@opscode.com>)
==> mybox:   5:  # Copyright:: Copyright (c) 2008-2010 Opscode, Inc.
==> mybox:   6:  # License:: Apache License, Version 2.0
==> mybox:   7:  #
==> mybox:   8:  # Licensed under the Apache License, Version 2.0 (the "License");
==> mybox:   9:  # you may not use this file except in compliance with the License.
==> mybox: 
==> mybox: [2015-03-04T11:08:11+00:00] ERROR: Running exception handlers
==> mybox: [2015-03-04T11:08:11+00:00] ERROR: Exception handlers complete
==> mybox: [2015-03-04T11:08:11+00:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
==> mybox: [2015-03-04T11:08:11+00:00] FATAL: SyntaxError: /tmp/vagrant-chef-1/chef-solo-1/cookbooks/windows/libraries/windows_package.rb:239: syntax error, unexpected ':', expecting kEND
==> mybox:         provides :windows_package, os: "windows"
==> mybox:                                       ^
Chef never successfully completed! Any errors should be visible in the
output above. Please fix your recipes so that they properly complete.

说我没有编辑过这个食谱是有意义的,它可以正常使用厨师 - 客户手动执行它而不是流浪者,最重要的是,确切版本的红宝石应该执行配方说没有语法:

$ /opt/chef/embedded/bin/ruby -c myproject-cookbook/cookbooks/windows/libraries/windows_package.rb 
Syntax OK

您可以检查配方是否失败in github

cookbook文件夹中的cookbook是:

  • 7-拉链
  • chef_handler
  • 的java
  • 行家
  • myproject的

实际问题:

  1. 为什么这是&#34; windows_package&#34;食谱运行?
  2. 为什么厨师会抱怨语法错误而红宝石本身并不是

  3. 编辑(我几乎没有任何特权): 是的,厨师在版本10.14.2的客人&#34; mybox&#34;:

    中很奇怪
    vagrant@precise64:~$ chef-solo -v
    Chef: 10.14.2
    

    相反,主机中的chef-client处于由omnibus安装程序安装的版本...

    user@host$ chef-solo -v
    Chef: 12.1.0
    

    我认为主持人的厨师被复制到访客,然后在访客内部运行,我将重新检查配置并尝试安装正确的版本。

    谢谢!


    EDIT2: 它实际上是厨师版。看起来事先不需要在主机上安装厨师;相反,vagrant将它自己安装在guest上,选择它喜欢的版本。

    直到vagrant版本1.7.2才需要安装vagrant-omnibus插件才能选择要安装的版本。请参阅how to do it

    从1.7.2开始,人们可以在不需要任何插件的情况下完成,使用&#34; install&#34;和&#34;版本&#34;方法。文档here

    资料来源:Mazinlabs blog(日文)

1 个答案:

答案 0 :(得分:0)

我很确定这与盒子上安装的厨师版本有关:

==> mybox: [2015-03-04T11:08:09+00:00] INFO: *** Chef 10.14.2 ***

我无法确定,但我打赌你在使用ssh时尝试使用其他厨师版本。无论如何10.14.2已经很老了,你会发现最近的食谱错误。

IIRC有一个流浪汉插件安装/ upadte厨师(vagrant-omnibus?)