如何配置Chef Solo以在新的Vagrant盒子上安装Nginx?

前端之家收集整理的这篇文章主要介绍了如何配置Chef Solo以在新的Vagrant盒子上安装Nginx?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我是Chef的新手,文档(甚至是他们网站的主页)让我头晕目眩.我甚至不确定我是否将它用于正确的目的.

我的目的是设置一个Vagrantfile,告诉Chef Solo在我启动一个新盒子时自动安装一些软件.这是Chef Solo的主要用途之一,我是否正确?

我不确定这是否是“地球上最严峻的基础设施挑战”之一,但无论如何.

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

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

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

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

当我跑出流浪汉时,我得到了一些错误,一些烹饪书没有找到(构建必不可少,适当等),所以我从他们适当的回购克隆了它们.现在,当我流浪,我得到这个输出

[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

厨师从未成功完成!任何错误都应该在上面的输出中可见.请修复您的食谱,以便它们正确完成.

如何修复我的食谱以使其正确完成?

解决方法

为了更有效地使用厨师我建议安装以下vagrant插件
vagrant plugin install vagrant-omnibus
vagrant plugin install vagrant-berkshelf

Berkshelf是用于管理食谱依赖性的工具. omnibus plugin对于确保您使用最新版本的厨师非常有用.

以下示例演示了如何轻松安装Nginx之类的东西.

├── Berksfile
└── Vagrantfile

Berkshelf

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

site :opscode

cookbook "Nginx"

Vagrantfile

以下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上同样有效.

猜你在找的CSS相关文章