0

我有一个项目目录

/
  VagrantFile
  /cookbooks
    /nginx
      ..

VagrantFile

# -*- 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

我运行vagrant 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 目录来自克隆https://github.com/opscode-cookbooks/nginx

我究竟做错了什么?

4

2 回答 2

0

问题似乎是虚拟机上不喜欢某些日志记录设置的 Chef 版本,因此我需要在节点上升级 Chef,并将 ruby​​ 升级为一个单独的问题,因为gem install失败了。

sudo apt-get update
sudo apt-get install ruby-dev
sudo gem install chef
于 2013-03-22T17:38:50.383 回答
0

我遇到了同样的问题,我正在添加一个 bash 文件来检查您是否安装了厨师的综合安装,如果没有安装它。它还不能完美地工作,但我觉得我已经很接近了,它应该可以解决你的问题。

在您致电 chef 上方的 Vagrant 文件中,取消注释此行:

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

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

#! /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

注意:我直接从 Opscode 站点获得的 curl 命令行可能与您的系统不同。请参阅站点以获取正确的线路。

于 2013-06-26T14:10:50.300 回答