0
votes

I have a cookbooks folder in root project which also has the Vagrantfile. I only have a couple of cookbooks (starter depends on "apt" and database depends on mysql). These cookbooks were generated with berks cookbook.

Now problem is when it comes to set the config.berkshelf.berksfile_path in the Vagrantfile, I don't know if put ./cookbooks/starter/Berksfile or ./cookbooks/database/Berksfile since both cookbooks have berks dependencies.

I tried multiple options like move these cookbooks into cookbooks-src and iterate through each of them and execute berks vendor ../../cookbooks but didn't work since the second vendor generated cookbooks would overwrite previous one.

Tried also vendor each cookbooks dependencies into ./cookbooks/the-cookbook/cookbooks but vagrant doesn't recognize them.

This is my vagrant file:

Vagrant.configure(2) do |config|
  config.vm.box = "ubuntu/trusty64"
  config.vm.hostname = "chef-DK"

  config.vm.provider "virtualbox" do |v|
    v.customize ["modifyvm", :id, "--cpuexecutioncap", "67"]
    v.memory = 537
  end

  config.berkshelf.enabled = true
  config.berkshelf.berksfile_path = "./cookbooks/starter/Berksfile"
  config.vm.provision :chef_solo do |chef|
    chef.install = false  

    chef.run_list = [
      'recipe[starter::default]',
      'recipe[database::default]'
    ]
  end
end

project/
├── cookbooks/
│   ├── database
│   │         ├── recipes
│   │         ├── Berksfile
│   │         └── metadata.rb
│   └── starter
│             ├── recipes
│             ├── Berksfile
│             └── metadata.rb
└── Vagrantfile

============================================

content of starter/metadata.rb:

name             'starter'
maintainer       'YOUR_NAME'
maintainer_email 'YOUR_EMAIL'
license          'All rights reserved'
description      'Installs/Configures starter'
long_description 'Installs/Configures starter'
version          '0.1.0'

depends 'apt', '~> 3.0.0'

content of starter/Berksfile:

source "https://supermarket.chef.io"

metadata

cookbook 'apt', '~> 3.0.0'

============================================

content of database/metadata.rb:

name 'database'
maintainer 'The Authors'
maintainer_email '[email protected]'
license 'all_rights'
description 'Installs/Configures database'
long_description 'Installs/Configures database'
version '0.1.0'

depends 'mysql', '~> 6.0'

content of database/Berksfile:

source "https://supermarket.chef.io"

metadata

cookbook 'mysql', '~> 6.1.3'
1
Could you add the output of your Berksfiles and the depends in your metadata.rb files? just to check that you don't have any unusual dependence. Probably you will need to create another third Berksfile that includes the other two cookbooks.zuazo
I just added what you requested to the main question. I tried to add a berksfile in the root folder where these couple of cookbooks are located but then vagrant would complain that there is no metadata.rb next to the berksfile. I tried a workaround which actually work but is not what I'm looking for. I just put in my starter/berksfile a dependency to ther database cookbook through path attribute and also move all dependencies of the database/berksfile into starter/berksfile and finally vendor starter cookbook but again this is not what I'm looking for when it actually work as I wanted to.Andres Murillo

1 Answers

0
votes

First of all I would like to clarify that the berkshelf metadata instruction reads the cookbook metadata.rb (i.e., your cookbook entries in your Berksfiles seem redundant).

In your case you could create a Berksfile in you main project/ directory (next to your Vagrantfile) with the following content:

source 'https://supermarket.chef.io'

cookbook 'database', path: 'cookbooks/database'
cookbook 'starter', path: 'cookbooks/starter'

And then add it to your Vagrantfile:

config.berkshelf.berksfile_path = './Berksfile'

I think your problem is that you are adding a metadata instruction in your vagrant Berksfile and that's why you are getting the "there is no metadata.rb" error.