0
votes

I'm having a syntax error on an official recipe. When I tried to run this recipe from inside a vagrant box, it worked fine. I used:

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

Now I'm trying to provision the box with chef-solo, as chef-client requires a server and keys. It should be equivalent.

This is my Vagrantfile, where I have two machines, each provisioned by some chef recipes. I also set ssh to X mode, DNS redirection for name resolving, the memory assigned to each machine, and the shared folder.

The error appears if I add to the runlist recipe1, recipe2, or even without any recipy in runlist.

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

The actual error comes from an official cookbook, windows, which I don't know why chef runs it if I haven't specified a single recipe to run.

$ 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 (<[email protected]>)
==> mybox:   3:  # Author:: Christopher Walters (<[email protected]>)
==> mybox:   4:  # Author:: Tim Hinderliter (<[email protected]>)
==> 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.

It's relevant to say that I haven't edited this recipe, that it works fine with chef-client executing it manually instead of from vagrant, and most important, that the exact version of ruby that should be executing the recipe says there is no syntax:

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

You can check the recipe failing in github

The cookbooks in the cookbooks folder are:

  • 7-zip
  • ark
  • chef_handler
  • java
  • maven
  • myproject
  • windows

Actual questions:

  1. Why is this "windows_package" recipe run?
  2. Why chef complains about a Syntax error and ruby by itself doesn't?

EDIT (I have a hardly any privilege): Yes, chef is strangely at version 10.14.2 in guest "mybox":

vagrant@precise64:~$ chef-solo -v
Chef: 10.14.2

Instead, chef-client in host is at the version installed by the omnibus installer...

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

I thought that host's chef was replicated to the guest and then run inside guest, I will recheck provisioning and try to make it install the proper version.

Thanks!


EDIT2: It was actually the chef version. It looks like no chef needs to be installed on the host beforehand; instead, vagrant installs it by itself on guest, choosing the version it likes.

Until vagrant version 1.7.2 one needed to install vagrant-omnibus plugin in order to choose the version to install. See how to do it.

Starting from 1.7.2, one can do it without the need of any plugin, using "install" and "version" methods. The doc here.

Source: Mazinlabs blog (in japanese)

1

1 Answers

0
votes

I'm pretty sure this has to do with the chef version installed on the box:

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

I can't be sure but I bet you're using a different chef version when trying from ssh. Anyway 10.14.2 is pretty old and you'll hit errors with recent cookbooks.

IIRC there's a vagrant plugin to install/upadte chef (vagrant-omnibus ?)