How to reference cookbooks from different location in metadata.rb?

I have my own Chef cookbook located in the cookbook's default path. However, due to the fact that I dont want to store external cookbooks into git version control, I have created a new path for external cookbooks specified in the Berkfile. So the structure of my chef stuff is like:

|     |_myCookbook 
|        |__metadata.rb
|     |_windows 
|__ ... ...

The issue is since I store all the cookbooks in 2 different places and when run ChefSpec for my own cookbook, the metadata.rb complains that it couldn't find the other external cookbooks that I referenced.

# metadata.rb
name 'myCookbook'
chef_version '>= 14.0'
depends 'windows', '~> 5.3.0'

I have googled this issue and tried to find a way to reference the path for the windows cookbook, but still haven't found any solution. Just wondering if you guys have any ideas about this?

I got an unideal workout which is to move all the cookbooks under the default cookbook path and add all the external cookbooks into the .gitignore file. However, this solution is not really nice in terms of managing all the cookbooks in the long-term.


You should be able to set cookbook_path as an array of paths:

# spec_helper.rb
require 'chefspec'
require 'chefspec/cacher'

RSpec.configure do |config|
  config.cookbook_path =['../../cookbooks', '../../external_cookbooks']

You can put this in your spec_helper and include it in each spec file or manually specify it when you create the runners

1 Like