8

I'm new to Chef and the documentation (even the home page of their website) makes my head spin. I'm not even sure if I'm using it for the correct purpose.

My intent is to setup a Vagrantfile that tells Chef Solo to install some software automatically when I spin up a new box. That is one of Chef Solo's intended uses, am I correct?

I'm not really sure if that qualifies as one of "the hardest infrastructure challenges on the planet", but whatever.

My first goal is to get Chef Solo to install nginx for me. In my project, I've cloned the cookbook for nginx:

$ git clone https://github.com/opscode-cookbooks/nginx.git cookbooks/nginx

I edited my Vagrantfile to look like this:

Vagrant.configure("2") do |config|
  config.vm.box = "opscode-ubuntu-1204"
  config.vm.provision :chef_solo do |chef|
    chef.add_recipe "nginx"
  end
end

When I ran vagrant up, I got some errors that some cookbooks weren't found (build-essential, apt, etc), so I cloned them from their appropriate repos. Now, when I vagrant up, I'm getting this output:

[2013-10-01T20:31:03+00:00] INFO: Processing package[nginx] action install (nginx::package line 38)    

Error executing action `install` on resource 'package[nginx]'
Chef::Exceptions::Exec
----------------------

apt-get -q -y install nginx=1.1.19-1ubuntu0.1 returned 100, expected 0

Resource Declaration:
---------------------
# In /tmp/vagrant-chef-1/chef-solo-1/cookbooks/nginx/recipes/package.rb

 38: package node['nginx']['package_name'] do
 39:   notifies :reload, 'ohai[reload_nginx]', :immediately
 40: end
 41: 

Compiled Resource:
------------------
# Declared in /tmp/vagrant-chef-1/chef-solo-1/cookbooks/nginx/recipes/package.rb:38:in `from_file'

package("nginx") do
  action :install
  retries 0
  retry_delay 2
  package_name "nginx"
  version "1.1.19-1ubuntu0.1"
  cookbook_name :nginx
  recipe_name "package"
end

[2013-10-01T20:31:08+00:00] INFO: Running queued delayed notifications before re-raising exception
[2013-10-01T20:31:08+00:00] ERROR: Running exception handlers
[2013-10-01T20:31:08+00:00] ERROR: Exception handlers complete
[2013-10-01T20:31:08+00:00] FATAL: Stacktrace dumped to /tmp/vagrant-chef-1/chef-stacktrace.out
[2013-10-01T20:31:08+00:00] FATAL: Chef::Exceptions::Exec: package[nginx] (nginx::package line 38) had an error: Chef::Exceptions::Exec: apt-get -q -y install nginx=1.1.19-1ubuntu0.1 returned 100, expected 0

Chef never successfully completed! Any errors should be visible in the output above. Please fix your recipes so that they properly complete.

How can I fix my recipes so that they properly complete?

4

2 回答 2

23

为了更有效地使用 chef,我建议安装以下 vagrant 插件:

vagrant plugin install vagrant-omnibus
vagrant plugin install vagrant-berkshelf

Berkshelf是一个管理说明书依赖的工具。综合插件有助于确保您使用的是最新版本的 chef。

以下示例演示了安装 nginx 之类的东西变得多么容易。

例子

├── Berksfile
└── Vagrantfile

伯克谢尔夫

列出所需的说明书。Berkshelf 将从 opscode 社区网站下载它们(和依赖项)。

site :opscode

cookbook "nginx"

流浪文件

以下 vagrant 文件将安装 nginx,使其在主机的 8080 端口上可用:

Vagrant.configure("2") do |config|

  # Box details
  config.vm.box = "Berkshelf-CentOS-6.3-x86_64-minimal"
  config.vm.box_url = "https://dl.dropbox.com/u/31081437/Berkshelf-CentOS-6.3-x86_64-minimal.box"

  # Plugins
  config.berkshelf.enabled = true
  config.omnibus.chef_version = :latest

  # Network
  config.vm.network :forwarded_port, guest: 80, host: 8080

  # Chef solo provisioning
  config.vm.provision :chef_solo do |chef|
    chef.add_recipe "nginx"
  end

end

笔记:

  • 此示例使用 CentOS。应该在 Ubuntu 上同样好用。
于 2013-10-01T22:25:46.110 回答
0

嗨,我遇到了同样的问题,在搜索时偶然发现了您的问题。我已经简单地解决了它,包括 APT 配方。之所以需要它,是因为您必须先对新实例进行 apt-get update 才能安装软件包。就这样。

于 2013-10-22T16:57:19.773 回答