我正在尝试创建一个使用rbenv,Postgres和JDK配置计算机的Chef cookbook,但我遇到了依赖项问题。
我使用(如果我没记错的话)chef generate app chef-project
创建了一个厨师仓库,并开始将规格放在一起。当使用rbenv cookbook改进食谱时,我将其添加到Berksfile:
source 'https://supermarket.chef.io'
metadata
cookbook 'rbenv', '= 1.4.1'
并在食谱中引用它:
#
# 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'
然而,它给了我这个错误:
-----> 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)
将depends 'rbenv'
添加到食谱metadata.rb
并没有解决问题 - 它仍然给我一个错误,即找不到rbenv
。我还需要做些什么才能将其添加为依赖项?
回购协议看起来像这样:
.
├── 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
我的.kitchen.yml
看起来像这样:
---
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:
编辑:使用chef_solo
代替chef_zero
会给我同样的问题,所以没有骰子。
答案 0 :(得分:1)
您希望将其添加到metadata.rb
中,而不是将其添加到Berksfile中:
depends 'rbenv', '1.4.1'
告诉Chef将其作为依赖项加载,仅将其添加到Berksfile中。