简体   繁体   English

如何在厨师中运行带有依赖项的食谱?

[英]How run cookbook with dependencies in chef?

I have configured workstation up this step in get started (OS redhat 6.5). 我已经在入门(OS redhat 6.5)的这一步骤中配置了工作站。 I have launched a node. 我已经启动了一个节点。 I modified a cookbook like that: 我像这样修改了食谱:

myCookbook/metadata.rb myCookbook / metadata.rb

name             'myCookbook'
maintainer       'YOUR_COMPANY_NAME'
maintainer_email 'YOUR_EMAIL'
license          'All rights reserved'
description      'Installs/Configures myCookbook'
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version          '0.1.0'

depends 'maven'

Eg only depends 'maven' string was added after knife cookbook create myCookbook was executed. 例如,仅在执行knife cookbook create myCookbook之后才添加depends 'maven'字符串。

myCookbook/recipes/default.rb myCookbook /食谱/default.rb

maven 'spring-context' do
  group_id 'org.springframework'
  version  '4.0.4.RELEASE'
  dest     '/root/chef-repo/'
  repositories ['http://repo.maven.apache.org/maven2/']
end

Then I run: 然后我运行:

knife cookbook upload myCookbook

Now I am trying: 现在我正在尝试:

knife bootstrap 192.168.1.37 --ssh-user root --ssh-password '123456' --sudo --use-sudo-password --node-name node-with-maven-run --run-list 'recipe[myCookbook]'

And get: 得到:

ERROR: Cookbook myCookbook depends on cookbooks which are not currently
ERROR: being uploaded and cannot be found on the server.
ERROR: The missing cookbook(s) are: 'maven' version '>= 0.0.0'

How install all cookbook to chef server from that mtCookbook depends? 如何将所有食谱从mtCookbook安装到厨师服务器?

See here 看这里

Or just type knife cookbook upload --help and it will show you the following line (along others): 或只输入knife cookbook upload --help ,它就会向您显示以下行(以及其他内容):

--include-dependencies Also upload cookbook dependencies

So knife cookbook upload myCookbook --include-dependencies is your answer 因此, knife cookbook upload myCookbook --include-dependencies是您的答案

You'll need to have the maven cookbook on your workstation too, by knife cookbook site install maven or any other way to have a directory called maven in your local cookbook_path containing a cookbook where the metatada.rb file as a key name with value maven 你需要有maven在工作站上的菜谱也被knife cookbook site install maven或任何其他方式有一个叫做目录maven在本地cookbook_path含有菜谱,其中metatada.rb文件作为一个关键name与价值行家

@rastasheep has described how the berkshelf tool is now bundled with the chefdk package. @rastasheep已经描述了berkshelf工具现在如何与chefdk软件包捆绑在一起。

It's really easy to use and worth learning. 它真的很容易使用,值得学习。 It's designed to work like the gem bundler tool. 它的设计类似于宝石捆绑器工具。

Example

└── myCookbook
    ├── Berksfile       <-- Berkshelf configuration file
    ├── Berksfile.lock  <-- Lock file generated by Berkshelf
    ├── metadata.rb
    ├── README.md
    └── recipes
        └── default.rb

Berksfile Berksfile

source "https://supermarket.getchef.com"

metadata

The "source" directive tells berkshelf where to download dependencies from. “源”指令告诉berkshelf从何处下载依赖项。 The "metadata" directive tells berkshelf to take dependencies from the cookbook metadata. “元数据”指令告诉berkshelf从食谱元数据中获取依赖项。

Using Berkshelf 使用Berkshelf

The "install" command will download the cookbook dependencies (Cached under ~/.berkshelf) “安装”命令将下载食谱依赖项(缓存在〜/ .berkshelf下)

$ cd myCookbook
$ berks install
Resolving cookbook dependencies...
Fetching 'myCookbook' from source at .
Fetching cookbook index from https://supermarket.getchef.com...
Installing maven (1.2.0)
Installing 7-zip (1.0.2)
Installing ark (0.9.0)
Installing chef_handler (1.1.6)
Installing java (1.29.0)
Installing windows (1.34.8)
Using myCookbook (0.1.0) from source at .

Berkshelf can also upload all the cookbooks into your chef server Berkshelf还可以将所有食谱上传到您的厨师服务器

$ berks upload
Uploaded 7-zip (1.0.2) to: 'http://127.0.0.1:8889/'
Uploaded ark (0.9.0) to: 'http://127.0.0.1:8889/'
Uploaded chef_handler (1.1.6) to: 'http://127.0.0.1:8889/'
Uploaded java (1.29.0) to: 'http://127.0.0.1:8889/'
Uploaded maven (1.2.0) to: 'http://127.0.0.1:8889/'
Uploaded myCookbook (0.1.0) to: 'http://127.0.0.1:8889/'
Uploaded windows (1.34.8) to: 'http://127.0.0.1:8889/'

There is a few other options for managing cookbook cookbook and dependencies, such Berkshelf or Librarian-chef, where Berkshelf is more popular, and it's even included in Chef Development Kit, so if you use it you do not need to install it separately. 还有一些其他管理菜谱和依赖项的选项,例如Berkshelf或Librarian-chef,其中Berkshelf更受欢迎,甚至包括在Chef Development Kit中,因此,如果您使用它,则不需要单独安装。

After defining sources you just need to define which cookbooks you want their versions and cookbook manager will resolve dependencies for all defined cookbooks and it will install them for you, and if you want you can vendor them too. 定义源之后,您只需要定义想要哪些版本的食谱,并且食谱管理器将解析所有已定义食谱的依赖关系,并将为您安装它们,如果您愿意,也可以提供它们。 Beside that they have an option to upload specific cookbook, without worrying about upload dependencies. 此外,他们可以选择上传特定食谱,而不必担心上传依赖性。

For more info how to use those tools consult official websites: 有关如何使用这些工具的更多信息,请访问官方网站:

In general for managing small projects you can use knife's upload flag for uploading dependencies. 通常,对于管理小型项目,您可以使用knife的upload标志来上传依赖项。

-d, --include-dependencies
    Use to ensure that when a cookbook has a dependency on one (or more) cookbooks, those cookbooks will also be uploaded.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM