如何为超市食谱创建包装食谱?

How to create a wrapper cookbook for a supermarket cookbook?

我正在尝试使用 Chef 在必须包含 PostgreSQL 和 MsBuild 的 Ubuntu 服务器计算机 (18.04) 中创建一个环境(我将部署一个 asp.net 核心应用程序)。已经有用于设置的食谱 postgres in the supermarket, but I can't use them. I am following this tutorial

首先我创建了一个新的包装器食谱:

chef generate cookbook my_postgres

然后我将 metadata.rb 更改为如下所示:

name 'my_postgres'
maintainer 'The Authors'
maintainer_email 'you@example.com'
license 'All Rights Reserved'
description 'Installs/Configures my_postgres'
long_description 'Installs/Configures my_postgres'
version '0.1.0'
chef_version '>= 13.0'
depends 'postgresql'

而我的default.rb文件如下:

#
# Cookbook:: my_postgres
# Recipe:: default
#
# Copyright:: 2020, The Authors, All Rights Reserved.
include_recipe 'postgresql::default'

但是当我运行食谱时:

sudo chef-client --local-mode default.rb

我收到以下消息:

[2020-02-23T16:19:26+00:00] WARN: No config file found or specified on command line, using command line options.
[2020-02-23T16:19:26+00:00] WARN: No cookbooks directory found at or above current directory.  Assuming /home/hermano/my_postgres/recipes.
Starting Chef Client, version 14.7.17
resolving cookbooks for run list: []
Synchronizing Cookbooks:
Installing Cookbook Gems:
Compiling Cookbooks...
[2020-02-23T16:19:28+00:00] WARN: MissingCookbookDependency:
Recipe `postgresql::default` is not in the run_list, and cookbook 'postgresql'
is not a dependency of any cookbook in the run_list.  To load this recipe,
first add a dependency on cookbook 'postgresql' in the cookbook you're
including it from in that cookbook's metadata.


Running handlers:
[2020-02-23T16:19:28+00:00] ERROR: Running exception handlers
Running handlers complete
[2020-02-23T16:19:28+00:00] ERROR: Exception handlers complete
Chef Client failed. 0 resources updated in 01 seconds
[2020-02-23T16:19:28+00:00] FATAL: Stacktrace dumped to /home/hermano/.chef/local-mode-cache/cache/chef-stacktrace.out
[2020-02-23T16:19:28+00:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report
[2020-02-23T16:19:28+00:00] FATAL: Chef::Exceptions::CookbookNotFound: Cookbook postgresql not found. If you're loading postgresql from another cookbook, make sure y

确保在元数据中配置依赖关系

我错过了什么?

您的问题应该出在您当前的工作目录上,根据您的输出行 [2020-02-23T16:19:26+00:00] WARN: No cookbooks directory found at or above current directory. Assuming /home/hermano/my_postgres/recipes,您从该目录执行命令。应该是 /home/hermano/my_postgres/recipes

根据文档,您必须创建一个名为 cookbooks 的目录,并将您的 cookbooks 目录放在那里:

/home/hermano/cookbooks
/home/hermano/cookbooks/my_postgres

然后你应该在 cookbooks 目录上设置你的 cwd 并执行以下命令:

cd /home/hermano/cookbooks
sudo chef-client --local-mode --runlist "my_postgres::default.rb"