I'm using vagrant+chef. My chef cookbooks worked perfectly. Then I installed vagrant-berkshelf plugin and from that moment I could not use own cookbooks. Berkshelf overrides cookbooks directory and chef does not see my cookbooks when I use them. My config is like this:
config.berkshelf.enabled = true
config.vm.provision :chef_solo do |chef|
chef.add_recipe "qbaka-frontend"
end
With this configuration chef works only with cookbooks specified in Berksfile
but can't see my cookbooks in cookbooks
directory.
How can I work simultaneously with my & Berkshelf's cookbooks?
The goal of Berkshelf is to manage a cookbook outside of Chef repository in isolation. Berkshelf is a Command Line tool which can act as a source code management tool or a package manager like gem, apt, yum, etc. It replaces portions of knife like generating, uploading & downloading Cookbooks.
With single command ( berks install ), it downloads all dependent cookbooks (and their dependent cookbooks -- transitive dependencies) from their respective sources (may be from git repository or from supermarket). With another single command berks upload it uploads all these cookbooks to chef server.
The vagrant-berkshelf
plugin and Berkshelf in general is very cookbook-centric. Chef, however, is cookbook-repo centric. Installing the vagrant-berkshelf
plugin encourages you to use the cookbook-centric approach, treating each cookbook like its own software project.
You need to add each of the cookbooks in your cookbooks
directory to your Berksfile. There are a couple of approaches here:
If you only need one or two cookbooks, just add them using the Berkshelf path location:
cookbook 'bacon', path: '~/cookbooks/bacon'
If you want all your cookbooks, you can leverage Ruby here. A little-known secret is that the Berksfile
is executed as Ruby, so you can loop and be magical:
Dir['/Users/sethvargo/cookbooks/**'].each do |path|
cookbook File.basename(path), path: path
end
That will load each cookbook in that directory into your Berksfile (and thus Berkshelf)
Sources:
You have to specify the path to your cookbooks in your Berksfile
.
cookbook "artifact", path: "/Users/reset/code/artifact-cookbook"
See here: http://berkshelf.com/#path_location
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With