如何配置 Chef Solo 以在新的 Vagrant 机器上安装 Nginx? [英] How do I configure Chef Solo to install Nginx on a new Vagrant box?

查看:26
本文介绍了如何配置 Chef Solo 以在新的 Vagrant 机器上安装 Nginx?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Chef 的新手,文档(甚至是他们网站的主页)让我头晕目眩.我什至不确定我是否出于正确的目的使用它.

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.

我的目的是设置一个 Vagrantfile,它告诉 Chef Solo 在我启动一个新盒子时自动安装一些软件.这是 Chef Solo 的预期用途之一,我说得对吗?

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.

我的第一个目标是让 Chef Solo 为我安装 nginx.在我的项目中,我克隆了 nginx 的食谱:

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

我编辑了我的 Vagrantfile 看起来像这样:

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

当我运行 vagrant up 时,我遇到了一些错误,即找不到某些食谱(build-essentialapt 等),所以我从他们适当的存储库中克隆了它们.现在,当我 vagrant up 时,我得到了这个输出:

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?

推荐答案

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

To more effectively use chef I'd advise installing the following vagrant plugins:

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

Berkshelf 是一种用于管理说明书依赖项的工具.omnibus 插件 有助于确保您使用的是 Chef 的最新版本.

Berkshelf is a tool for managing cookbook dependencies. The omnibus plugin is useful to ensure you're using the latest revision of chef.

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

The following example demonstrates how easy it becomes to install something like nginx.

├── Berksfile
└── Vagrantfile

Berkshelf

列出所需的食谱.Berkshelf 将从 opscode 社区网站下载它们(和依赖项).

Berkshelf

Lists the required cookbooks. Berkshelf will download them (and dependencies) from the opscode community website.

site :opscode

cookbook "nginx"

流浪文件

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

Vagrantfile

The following vagrant file will install nginx, making it available on port 8080 of the host machine:

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 上应该同样有效.

这篇关于如何配置 Chef Solo 以在新的 Vagrant 机器上安装 Nginx?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆