5

I am fairly new to using chef, particularly with vagrant so this will most likely be a silly question to the more experienced users out there.

I am using this cookbook: https://github.com/opscode-cookbooks/application_nginx

I simply want to add my own site config (vhost).

It has to be one of the following:

  1. Add my own recipy and template directly to the cookbook
  2. Create my own cookbook that extends in some way the nginx cookbook to add only the specific behaviour i require.

Option 1 doesnt seem right to me and I dont have any idea on how to complete option 2 without having to completely separate cookbooks.

can anyone advise on how this is achieved?

1 Answers1

7

If you just want to configure a virtual host via nginx, it's likely you want to use the nginx cookbook. The application_nginx cookbooks is not meant to be used directly; rather it is a dependency of the application cookbook. If you are just getting started with chef I would avoid the application cookbook for now, since its use is somewhat complex.

The proper thing to do is to create your own cookbook for configuring your site, and use the nginx cookbook from within it. Treat third-party cookbooks as generic libraries for use in your own cookbooks, rather than something you fork and modify to make specific for your application(s).

For example, the default recipe in your cookbook might be:

# run the nginx::default recipe to install nginx
include_recipe "nginx"

# deploy your sites configuration from the 'files/' directory in your cookbook
cookbook_file "#{node['nginx']['dir']}/sites-available/example.com" do
  owner "root"
  group "root"
  mode  "0644"
end

# enable your sites configuration using a definition from the nginx cookbook
nginx_site "example.com" do
  enable true
end
javatarz
  • 103
  • 4
sciurus
  • 12,493
  • 2
  • 30
  • 49