How do I configure Chef Solo to install Nginx on a new Vagrant box?

陌路散爱 提交于 2019-11-28 06:06:15

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

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

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

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

Example

├── Berksfile
└── Vagrantfile

Berkshelf

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

site :opscode

cookbook "nginx"

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

Notes:

  • This example uses CentOS. Should work equally well on Ubuntu.

Hi I got into same problem and while searching stumbled upon your issue. I have solved it wi simple including APT recipe. Reason why you need it because you have to to apt-get update on the new instance before you can install packages. thats all.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!