我应该在chef存储库中哪里写`node.default`变量?

时间:2014-09-16 21:46:12

标签: chef berkshelf berksfile

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

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

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

并按berks vendor cookbooks安装了食谱。

然后我在服务器配置json文件中添加了"recipe[rbenv::user]"

根据文档,我必须设置一个变量node.default['rbenv']['user_installs']来安装rbenv。但我无法弄明白我应该把它写在哪里。

有人能告诉我在哪里以及如何编写变量?

**我的环境(编辑)

我这样使用local mode

$ 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'

角色/ 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)

1 个答案:

答案 0 :(得分:0)

通常你会把它放在一个角色或包装食谱中。如果您不熟悉Chef,那么角色可能最简单:

default_attributes({
  'rbenv' => {
    'user_installs' => whatever,
  },
})