Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I'm provisioning a Vagrant virtual machine with Chef and it's amazing, but I'm unsure where I should put code to configure software installed by 3rd-party chef recipes.

For example, I'm installing NGINX with this recipe but I need to configure the default virtual host to serve content from /vagrant/public instead of /var/www/nginx-default.

Should I change the template of the 3rd-party recipe, or create another recipe that reconfigures it?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

A couple of things:

Since the writing fo this question, Opscode has split out their repository structure to be one-repo-per-cookbook to make the project a lot clearer.

The up-to-date released, stable nginx cookbook can be found here: http://community.opscode.com/cookbooks/nginx

As to serve web pages from an alternate container:

The convention to do something like this would be to write a simpler cookbook, that leverages the nginx cookbook but provides you with a way to "do what you want".

Since the default nginx installation drops a config file and sets the source dir, a way I would do this in a "wrapper" cookbook is:

  1. Create my cookbook
  2. Declare depends 'nginx' in metadata.rb
  3. In my cookbook's attributes/default.rb, set the following attribute to false:

    default['nginx']['default_site_enabled'] = false
    
  4. In my recipes/default.rb, have:

    include_recipe 'nginx'
    
    cookbook_file '/etc/nginx/sites-available/mycustomwebapp'
    
    nginx_site 'mycustomwebapp' do
      action :enable
    end
    
  5. Create an nginx conf file that looks like this in files/default/mycustomwebapp:

    server {
        root /vagrant/public;
        index index.html index.htm;
            blah blah...
    }
    

Then you should be good to go!

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.