1

I want to use [chef-rbenv][1] cookbook.

I created a Berksfile in a chef-repo top directory like this:

source "https://api.berkshelf.com"
cookbook 'rbenv'

And installed cookbook by berks vendor cookbooks.

Then I added a "recipe[rbenv::user]" to server config json file.

According to the document I must set a variable node.default['rbenv']['user_installs'] to install rbenv. But I couldn't figure out where I should write it.

Can anyone show me where and how should I write the variable?

**My Environments (Edit)

I'm using local mode like this:

$ sudo chef-client --local-mode -c solo.rb -j localhost.json

solo.rb

base = File.expand_path('..', __FILE__)
file_cache_path "/tmp/chef-solo"
cookbook_path ["#{base}/site-cookbooks", "#{base}/cookbooks"]
role_path "#{base}/roles"

localhost.json

{
    "run_list" : [
    "recipe[rbenv::user]"
    ]
}

Berksfile

source "https://api.berkshelf.com"

cookbook 'rbenv'

roles/rbenv.rb

name "rbenv"

default_attributes({
                       'rbenv' => {
                           'user_installs' => {
                               'user'    => 'ironsand',
                               'rubies'  => ['1.9.3-p0'],
                               'global'  => '1.9.3-p0',
                           }
                       },
                   })

And this is the error when I run the command:

Starting Chef Client, version 11.14.6
[2014-09-18T03:56:08+09:00] WARN: Child with name 'vm-mint.json' found in multiple directories: /home/ironsand/my_chef_repo/nodes/vm-mint.json and /home/ironsand/my_chef_repo/nodes/vm-mint.json
resolving cookbooks for run list: ["rbenv::user"]
Synchronizing Cookbooks:
  - git
  - rbenv
  - dmg
  - yum-epel
  - build-essential
  - apt
  - windows
  - runit
  - ohai
  - yum
  - chef_handler
Compiling Cookbooks...

================================================================================
Recipe Compile Error
================================================================================

Chef::Exceptions::RecipeNotFound
--------------------------------
could not find recipe user for cookbook rbenv


Running handlers:
[2014-09-18T03:56:10+09:00] ERROR: Running exception handlers
Running handlers complete
[2014-09-18T03:56:10+09:00] ERROR: Exception handlers complete
[2014-09-18T03:56:10+09:00] FATAL: Stacktrace dumped to /tmp/chef-solo/chef-stacktrace.out
Chef Client failed. 0 resources updated in 3.019030351 seconds
[2014-09-18T03:56:10+09:00] ERROR: could not find recipe user for cookbook rbenv
[2014-09-18T03:56:10+09:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)
ironsand
  • 14,329
  • 17
  • 83
  • 176

1 Answers1

0

Generally you would put this in a role or wrapper cookbook. If you are unfamiliar with Chef, a role is probably easiest:

default_attributes({
  'rbenv' => {
    'user_installs' => whatever,
  },
})
coderanger
  • 52,400
  • 4
  • 52
  • 75
  • Maybe can you tell me how to write a role? I struggled already hours about this problem, I even read again chef's book. But I'm still stuck with this. – ironsand Sep 17 '14 at 19:04
  • 1
    I think that goes a bit beyond what I can fit on here. Chef Software and many other places (myself included) offer Chef training, might want to start there. learnchef.com is also a place to start, though I'm not as much of a fan as I once was. – coderanger Sep 17 '14 at 19:14