Book Image

Chef Infrastructure Automation Cookbook Second Edition

By : Matthias Marschall
Book Image

Chef Infrastructure Automation Cookbook Second Edition

By: Matthias Marschall

Overview of this book

Table of Contents (14 chapters)
Chef Infrastructure Automation Cookbook Second Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Creating nginx virtual hosts


Assuming you have nginx installed, you want to manage your websites with Chef. You need to create an nginx configuration file for your website and upload your HTML file(s). Let's see how to do this.

Getting ready

Make sure that you have a cookbook named my_cookbook, as described in the Creating and using cookbooks recipe in Chapter 1, Chef Infrastructure.

  1. Create Berksfile in your Chef repository including my_cookbook:

    mma@laptop:~/chef-repo $ subl Berksfile
    
    cookbook 'my_cookbook', path: './cookbooks/my_cookbook'
  2. Create or edit a role called web_server with the following content:

    mma@laptop:~/chef-repo $ subl roles/web_server.rb
    
    name "web_server"
    run_list "recipe[my_cookbook]"
    
    default_attributes "nginx" => {
      "init_style" => "init",
      "enable_default_site" => false
    }
  3. Upload the role to the Chef server:

    mma@laptop:~/chef-repo $ knife role from file web_server.rb
    
    Updated Role web_server!
  4. Add the web_server role to your node's run list:

    mma@laptop:~/chef-repo...