0

I'm trying to create a Chef cookbook for provisioning a machine with rbenv, Postgres, and the JDK, but I'm running into problems with dependencies.

I created a Chef repo using (if I remember correctly) chef generate app chef-project, and started putting the specs together. When it came time to improve the cookbook by using the rbenv cookbook, I added it to the Berksfile:

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

metadata

cookbook 'rbenv', '= 1.4.1'

and referenced it in the recipe:

#
# Cookbook Name:: chef-project
# Recipe:: default
#
# Copyright (c) 2015 The Authors, All Rights Reserved.

# Install rbenv

include_recipe 'rbenv::default'
include_recipe 'rbenv::ruby_build'

# Install jruby

rbenv_ruby 'jruby-1.7.19'

# Install bundler

rbenv_gem 'bundler' do
  ruby_version 'jruby-1.7.19'
end

package 'default-jdk'
package 'postgresql'

However, it gives me this error:

-----> Converging <default-ubuntu-1404>...
       Preparing files for transfer
       Preparing dna.json
       Preparing cookbooks from project directory
       Removing non-cookbook files before transfer
       Preparing validation.pem
       Preparing client.rb
-----> Chef Omnibus installation detected (install only if missing)
       Transferring files to <default-ubuntu-1404>
       Starting Chef Client, version 12.6.0
       resolving cookbooks for run list: ["chef-project::default"]
       Synchronizing Cookbooks:
         - chef-project (0.1.0)
       Compiling Cookbooks...
       [2015-12-29T17:41:08+00:00] WARN: MissingCookbookDependency:
       Recipe `rbenv::default` is not in the run_list, and cookbook 'rbenv'
       is not a dependency of any cookbook in the run_list.  To load this recipe,
       first add a dependency on cookbook 'rbenv' in the cookbook you're
       including it from in that cookbook's metadata.


       ================================================================================
       Recipe Compile Error in /tmp/kitchen/cache/cookbooks/chef-project/recipes/default.rb
       ================================================================================

       Chef::Exceptions::CookbookNotFound
       ----------------------------------
       Cookbook rbenv not found. If you're loading rbenv from another cookbook, make sure you configure the dependency in your metadata

       Cookbook Trace:
       ---------------
         /tmp/kitchen/cache/cookbooks/chef-project/recipes/default.rb:9:in `from_file'

       Relevant File Content:
       ----------------------
       /tmp/kitchen/cache/cookbooks/chef-project/recipes/default.rb:

         2:  # Cookbook Name:: chef-project
         3:  # Recipe:: default
         4:  #
         5:  # Copyright (c) 2015 The Authors, All Rights Reserved.
         6:
         7:  # Install rbenv
         8:
         9>> include_recipe 'rbenv::default'
        10:  include_recipe 'rbenv::ruby_build'
        11:
        12:  # Install jruby
        13:
        14:  rbenv_ruby 'jruby-1.7.19'
        15:
        16:  # Install bundler
        17:
        18:  rbenv_gem 'bundler' do


       Running handlers:
       [2015-12-29T17:41:08+00:00] ERROR: Running exception handlers

       [2015-12-29T17:41:08+00:00] ERROR: Exception handlers complete

       [2015-12-29T17:41:08+00:00] FATAL: Stacktrace dumped to /tmp/kitchen/cache/chef-stacktrace.out
       [2015-12-29T17:41:08+00:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report
       [2015-12-29T17:41:08+00:00] ERROR: Cookbook rbenv not found. If you're loading rbenv from another cookbook, make sure you configure the dependency in your metadata
       [2015-12-29T17:41:09+00:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)

Adding depends 'rbenv' to the cookbook's metadata.rb doesn't solve the issue - it still gives me an error about not finding rbenv. Is there something else I need to do to add it as a dependency?

The repo looks like this:

.
├── README.md
├── cookbooks
│   └── chef-project
│       ├── Berksfile
│       ├── Berksfile.lock
│       ├── chefignore
│       ├── metadata.rb
│       ├── recipes
│       │   └── default.rb
│       └── spec
│           ├── spec_helper.rb
│           └── unit
│               └── recipes
│                   └── default_spec.rb
└── test
    └── integration
        ├── default
        │   └── serverspec
        │       └── default_spec.rb
        └── helpers
            └── serverspec
                └── spec_helper.rb

and my .kitchen.yml looks like this:

---
driver:
  name: vagrant

provisioner:
  name: chef_zero

# Uncomment the following verifier to leverage Inspec instead of Busser (the
# default verifier)
# verifier:
#   name: inspec

platforms:
  - name: ubuntu-14.04

suites:
  - name: default
    run_list:
      - recipe[chef-project::default]
    attributes:

EDIT: Using chef_solo instead of chef_zero gives me the same issue, so no dice there.

r.pazyaquian
  • 73
  • 1
  • 6

1 Answers1

1

Rather than putting that in the Berksfile, you want to add it to your metadata.rb:

depends 'rbenv', '1.4.1'

That tells Chef to load it as a dependency, adding it only to the Berksfile does not.

coderanger
  • 52,400
  • 4
  • 52
  • 75
  • I added it to `metadata.rb`, and removed it from the Berksfile. I get a `No such cookbook: rbenv` error now. Do I need to actually download the cookbook itself? – r.pazyaquian Dec 30 '15 at 14:44
  • What folder is the `.kitchen.yml` in (and where are you running `kitchen test` from, which is probably the same folder)? It looks like you're trying to use kitchen in a mono-repo layout which is not the default. – coderanger Dec 30 '15 at 18:55