Provisioning with Chef

Video loading...

Join Drupalize.Me to watch this video

Join today and gain instant access to our entire video library.

Log in Sign up
  • 0:05
    with Emma Jane Westby
  • 0:08
    In this lesson, we're
  • 0:10
    going to be provisioning our machine with Chef.
  • 0:13
    I'm going to give you a starting kit to work from, because this can be
  • 0:16
    a little bit complicated to get all the bits and pieces working.
  • 0:19
    Now, I don't want to scare you off, but the reality
  • 0:22
    is you don't need to create your own Chef cookbooks to start.
  • 0:27
    I used someone else's for over a year very happily.
  • 0:31
    In this lesson, we're going to review Chef terminology,
  • 0:35
    review where cookbooks come from and can be downloaded
Loading ...

Provisioning with Chef

Loading...

In the previous lesson we discussed why you would want to use a configuration management tool. In this lesson we'll dive into how you automate the customization of new servers using the configuration management tool, Chef. Most of the work in assembling Chef recipes is already done for you. In this lesson you will be able to see how the pieces fit together; however, you will not be required to download each of the individual recipes to get everything working.

Lesson Outcomes

By the end of this lesson you will be able to describe how to add a Chef recipe to your setup, and re-provision Vagrant.

Lesson Summary

In the video, I've already setup Chef recipes, roles, and cookbooks for you. So instead of having to download all the pieces separately, you can just start with the code bundle for this lesson.

The outline provided below, however, includes each of the steps that I went through to prepare the configuration Chef recipes and roles that you're downloading.

Locating and Using Chef Cookbooks

  1. Locate Chef cookbooks for AMP stack, drush, and Drupal-specific PHP libraries you want pre-loaded.
  1. Place downloaded cookbooks into a sub-folder in your project directory. For example: chef-recipes/cookbooks.
  2. Create a role file to include all of the recipes (from each of the cookbooks) you want to load. This file can be placed into its own roles sub-directory. For example: chef-recipes/roles/lamp_stack.rb.
  3. Update the Vagrantfile to include:
  • path to cookbooks folder
  • path to roles folder
  • role(s) to load for this server
  • new values for any of the default settings for your recipes
  1. Provision the machine to enable / set-up / trigger the Chef configuration settings:
  • $ vagrant provision

The machine is now configured, but does not have Drupal installed. This is on purpose. You probably have a specific Drupal project you're working on.

Customizing Configuration Files to Use Chef Recipes

The role files contain a list of individual recipes, and/or roles that must be run to provision a specific type of server. Generally there are three or four parts to them.

  • name
  • description
  • run list (recipes and roles to add)
  • default settings for recipes (optional)

You should investigate the contents of the folder chef-recipes/roles. There is a detailed README tailored to this learning series, as well as the two roles that were created for this lesson.

The Vagrantfile is well commented, this section includes a quick references of the settings that have been updated in the file.

config.vm.provision :chef_solo do |chef|
# default settings
chef.cookbooks_path = "path_to_cookbooks_folder"
chef.roles_path = "path_to_roles_folder"

# roles and recipes to load
# recipes are generally loaded from within roles
chef.add_role "name_of_role"
chef.add_recipe "name_of_recipe"

# overrides for settings in recipes
chef.json = {
"name_of_recipe" => {
"name_of_setting" => "new_value",
},
}
end

Gotchas

  • If you are using these recipes for Drupal 8: the recipe provided for Drush won't work. You'll need to install Drush version 7 or greater (compatibility chart on the Drush project page).
  • You will probably want to update Chef with the omnibus plugin for Vagrant if the cookbook you want to add requires a newer version of Chef. On the host machine, install the plugin: $ vagrant plugin install vagrant-omnibus. Note: Chef must be updated before it is "run". For this lesson, I opted to use older versions of the cookbooks. 20 hours of my life spent working on upgrades that didn't work. The later scripts provide more flexibility (e.g. install ANY version of Drush, not just 5.8), but they work well enough for our needs.
  • Apt will only run if the cache is older than a day. The first time the machine is provisioned, this might be a problem. You can force updating the cache with the following setting in Vagrantfile: chef.json = { "apt" => {"compiletime" => true} }
  • If you are running into problems with permissions, refer to the tips in Sharing Files Between Your Guest and Host Machine.
  • Windows users will also need to download the following cookbooks, and add them to the directory you have configured for chef.cookbooks_path
    • chef-handler
    • chef-sugar
    • iis
    • windows
    • xml
    • yum
    • yum-epel
Downloads: 
Log in or sign up to download companion files.

Additional resources:
There are no resources for this video. If you believe there should be, please contact us.