1

我想用[chef-rbenv][1]食谱。

Berksfile在 chef-repo 顶级目录中创建了一个,如下所示:

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

并安装了食谱berks vendor cookbooks

然后我添加了一个"recipe[rbenv::user]"到服务器配置 json 文件。

根据文档,我必须设置一个变量node.default['rbenv']['user_installs']来安装 rbenv。但我不知道我应该在哪里写。

谁能告诉我应该在哪里以及如何编写变量?

**我的环境(编辑)

我是local mode这样使用的:

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

独奏.rb

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

本地主机.json

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

伯克斯文件

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

cookbook 'rbenv'

角色/rbenv.rb

name "rbenv"

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

这是我运行命令时的错误:

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)
4

1 回答 1

0

通常,您会将其放在角色或包装食谱中。如果您不熟悉 Chef,那么角色可能是最简单的:

default_attributes({
  'rbenv' => {
    'user_installs' => whatever,
  },
})
于 2014-09-16T22:17:19.730 回答