Migrating Custom Chef Recipes from V4 to V5


Custom chef recipes work differently on v5. All custom chef recipes that work on v2 and v4 need to be updated.

  1. Create the cookbooks/ directory. We recommend that you add the cookbooks/directory to the root of your application. If you have an existing cookbooks/ directory, move it to a temporary directory first.

      cd /path/to/app
      mv -i cookbooks cookbooks.v4
      mkdir cookbooks
  2. Create cookbooks/ey-custom/recipes/after-main.rb and cookbooks/ey-custom/recipes/metadata.rb.

    ey-custom/recipes/after-main.rb is now the entrypoint of custom chef recipes. You do not need the main/ directory that you used on v4.

      # cookbooks/ey-custom/metadata.rb
      name 'ey-custom'
  3. You can use custom chef recipes without copying the actual recipes. Addinclude_recipe and depends.

    On v5, you can use a chef recipe without adding a copy of the recipe to cookbooks/. Check out for the list of currently available recipes.

    For example, to use the delayed_job4 recipe that EY maintains, you only need to copy custom-delayed_job4 on to your cookbooks/ directory. Remove cookbooks/delayed_job4 if it still exists.

    On cookbooks/ey-custom/recipes/after-main.rb, add

      include_recipe 'custom-delayed_job4'

    On cookbooks/ey-custom/metadata.rb, add

      depends 'custom-delayed_job4'

    If you want to convert your existing custom chef recipes to v5 because we have not converted them yet or if it's something you wrote, follow steps 4-9.

  4. Copy the recipe from cookbooks.v4/ to cookbooks/. If you follow our instructions above, you will start with an empty cookbooks/.

      cd /path/to/app
      cp -pr cookbooks.v4/RECIPE_NAME cookbooks/
  5. Add cookbooks/RECIPE_NAME/metadata.rb.

      name 'RECIPE_NAME'
  6. Add include_recipe and depends. You always need to add these 2 for any recipe that you want to use.

    On cookbooks/ey-custom/recipes/after-main.rb, add

      include_recipe 'RECIPE_NAME'

    On cookbooks/ey-custom/metadata.rb, add

      depends 'RECIPE_NAME'
  7. Replace node['instance_role'], node['name'], and similar code and add ['dna']. We moved some data on dna.json from the "root" to dna{}. Check out/etc/chef/dna.json on a v5 instance to see the new format.'

    Run the code below to view the code that needs to be changed

      cd /path/to/cookbooks.v4/ # or cookbooks/
      grep -r "node\[\(:\|'\|\"\)\(applications\|engineyard\|environment\|instance_role\|members\|name\|users\|utility_instances\)" .
      # node['instance_role'] on v4
      # node ['name'] on v4

    Data specified on the attributes directory will not change. If you have

      default['redis'] = {'version' => "3.2.1"}

    you would still use

  8. Change the package versions. The v5 stack has new packages. Update your recipes to use these new versions. Refer to the table of common packages below.

  9. (Optional) Use a string instead of symbol when accessing node attributes. The code below are similar. Either can be used. Foodcritic (lint tool for Chef) suggests using a string.

      # use this
      # don't use this
Was this article helpful?
0 out of 1 found this helpful
Have more questions? Submit a request


Powered by Zendesk