Chef infra 试图通过chef solo将nginx安装到vagrant中会导致;命名错误:未定义的方法“[]';对于nil:NilClass“;

Chef infra 试图通过chef solo将nginx安装到vagrant中会导致;命名错误:未定义的方法“[]';对于nil:NilClass“;,chef-infra,Chef Infra,我有一个项目目录 / VagrantFile /cookbooks /nginx .. 在文件中: # -*- mode: ruby -*- # vi: set ft=ruby : Vagrant.configure("2") do |config| config.vm.box = "mediapop" config.vm.box_url = "http://cloud-images.ubuntu.com/precise/current/precise-s

我有一个项目目录

/
  VagrantFile
  /cookbooks
    /nginx
      ..
文件中

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|
  config.vm.box = "mediapop"
  config.vm.box_url = "http://cloud-images.ubuntu.com/precise/current/precise-server-cloudimg-vagrant-amd64-disk1.box"

  config.vm.provision :chef_solo do |chef|
    chef.add_recipe "nginx"
  end
end
我运行Waggrant up并获得:

$ vagrant halt && vagrant up
[default] Attempting graceful shutdown of VM...
Bringing machine 'default' up with 'virtualbox' provider...
[default] Setting the name of the VM...
[default] Clearing any previously set forwarded ports...
[default] Fixed port collision for 22 => 2222. Now on port 2201.
[default] Creating shared folders metadata...
[default] Clearing any previously set network interfaces...
[default] Preparing network interfaces based on configuration...
[default] Forwarding ports...
[default] -- 22 => 2201 (adapter 1)
[default] Booting VM...
[default] Waiting for VM to boot. This can take a few minutes.
[default] VM booted and ready for use!
[default] Configuring and enabling network interfaces...
[default] Mounting shared folders...
[default] -- /vagrant
[default] -- /tmp/vagrant-chef-1/chef-solo-1/cookbooks
[default] Running provisioner: VagrantPlugins::Chef::Provisioner::ChefSolo...
Generating chef JSON and uploading...
Running chef-solo...
stdin: is not a tty
[2013-03-22T09:16:26+00:00] INFO: *** Chef 10.12.0 ***
[2013-03-22T09:16:27+00:00] INFO: Setting the run_list to ["recipe[nginx]"] from JSON
[2013-03-22T09:16:27+00:00] INFO: Run List is [recipe[nginx]]
[2013-03-22T09:16:27+00:00] INFO: Run List expands to [nginx]
[2013-03-22T09:16:27+00:00] INFO: Starting Chef Run for vagrant-ubuntu-quantal-64
[2013-03-22T09:16:27+00:00] INFO: Running start handlers
[2013-03-22T09:16:27+00:00] INFO: Start handlers complete.
[2013-03-22T09:16:27+00:00] ERROR: Running exception handlers
[2013-03-22T09:16:27+00:00] ERROR: Exception handlers complete
[2013-03-22T09:16:27+00:00] FATAL: Stacktrace dumped to /tmp/vagrant-chef-1/chef-stacktrace.out
[2013-03-22T09:16:27+00:00] FATAL: NoMethodError: undefined method `[]' for nil:NilClass
Chef never successfully completed! Any errors should be visible in the
output above. Please fix your recipes so that they properly complete.
nginx目录来自克隆


我做错了什么?

问题似乎是虚拟机上的chef版本不喜欢某些日志设置,因此我需要升级节点上的chef,以及升级ruby,因为
gem安装失败

sudo apt-get update
sudo apt-get install ruby-dev
sudo gem install chef

我也遇到了同样的问题,我正在添加一个bash文件,检查您是否安装了chef的omnibus,如果没有安装它。它还没有完全发挥作用,但我觉得我已经接近了,它应该能解决你的问题

在您的Vagrant文件中,调用chef取消注释这一行:

config.vm.provision:shell,:path=>“bootstrapvm.sh”

然后创建
bootstrapvm.sh
文件。这应该在chef调用之前运行,它所要做的就是安装chef的综合版本(以及最新版本)


注意:我直接从Opscode站点获得的curl命令行可能与您的系统不同。有关正确的线路,请参考现场

你能把stacktrace从
stacktrace转储到/tmp/vagrant-chef-1/chef stacktrace.out
#! /bin/bash
apt-get install -y curl libcurl3
if ! [ -x /usr/bin/chef-solo ] ; then
  curl -L --insecure https://www.opscode.com/chef/install.sh | sudo bash
fi