指定要与Chef Solo一起运行的食谱 [英] Specifying which cookbooks to run with Chef Solo

查看:89
本文介绍了指定要与Chef Solo一起运行的食谱的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Chef-solo在本地测试我的菜谱,但我希望只能运行正在测试的菜谱。当前,chef-solo似乎将运行solo.rb中指定的cookbooks目录中的所有Cookbook。我已经在json属性文件中指定了运行列表,并在solo.rb中指定了json文件的位置,但这似乎无济于事。它至少解析所有其他食谱的属性,因为我有一个不适用于我的本地配置,并且在整个运行过程中都失败了。

I'm using chef-solo to test my cookbooks locally, but I want to be able to only run the cookbook(s) that I'm testing. Currently, it seems like chef-solo will run all cookbooks in the cookbooks directory specified in solo.rb. I've specified the run list in the json attributes file and specified the location of the json file in solo.rb, but that doesn't seem to help. It at least parses the attributes for all the other cookbooks, because I have one that doesn't work for my local configuration and it fails the entire run.

最佳解决方案到目前为止,我发现将需要测试的食谱移动到另一个目录,并在solo.rb中进行指定。有更好的方法吗?

The best solution I've found so far is to move the cookbook(s) I need for testing to a different directory and specify that in solo.rb. Is there a better way to do it?

推荐答案

更新:Chef-solo不再是与厨师客户分离的工具。从文档

Update: chef-solo is no longer a "separate" tool from chef-client. From the documentation:


chef-solo是一种命令,它以不需要Chef服务器来收敛食谱的方式执行Chef-client。 chef-solo使用chef-client的Chef本地模式,并且不支持chef-client /服务器配置中存在的以下功能

chef-solo is a command that executes chef-client in a way that does not require the Chef server in order to converge cookbooks. chef-solo uses chef-client’s Chef local mode, and does not support the following functionality present in chef-client / server configurations

更改已在 Chef版本12.11 中实现,符合社区RFC 。它于2016年6月8日发布。下面描述的旧行为(尽管是从4年前开始)可以在-legacy-mode 中使用。 chef-solo 的参数。

This change was implemented in Chef version 12.11, which fulfills the community RFC. This was released on June 8, 2016. The old behavior, which is described below (albeit from 4 years ago at this time), is available with the --legacy-mode argument to chef-solo.

有关Chef Solo的最新信息,请阅读< a href = https://docs.chef.io/chef_solo.html rel = nofollow noreferrer>官方文档

For the most current and up to date information about Chef Solo, please read the official documentation

我的原始答案如下:

厨师(单独或客户)不会运行所有食谱。

Chef (solo OR client) does not "run" all the cookbooks.

它按以下顺序加载所有菜谱中的Ruby文件:

It loads all the cookbook's Ruby files in the following directories, in this order:


  • 库/ *。rb

  • 提供者/ *。rb

  • 资源/ *。rb

  • 属性/ * .rb

  • definitions / *。rb

  • libraries/*.rb
  • providers/*.rb
  • resources/*.rb
  • attributes/*.rb
  • definitions/*.rb

然后,它会加载所有食谱在节点的扩展运行列表中。使用 chef-solo ,它来自 -j 随附的JSON文件,或者可以在属性文件中完成-

Then, it loads all the recipes that are in the node's expanded run list. With chef-solo, this comes from a JSON file supplied with -j, or can be done in attributes files - however the latter is deprecated and not recommended.

扩展运行列表中通过 include_recipe 也被加载。 Chef通过将食谱评估为Ruby代码来加载食谱。当遇到遇到被识别为资源或定义的红宝石代码时,它将资源添加到资源集合中,资源集合是所有资源的数字顺序索引哈希。定义是特殊的,因为Chef将它们包含的资源(而不是定义本身)添加到资源集合。通过 include_recipe 将包含的食谱资源插入到位,然后Chef继续包含的食谱。

Any recipes that are included by those in the expanded run list via include_recipe are also loaded. Chef loads recipes by evaluating them as Ruby code. When it encounters ruby code that it recognizes to be a resource, or a definition, it adds the resource to the Resource Collection, which is an numerically ordered indexed hash of all the resources. Definitions are special, in that Chef adds the resources they contain, not the definition itself, to the Resource Collection. Included recipes' resources via include_recipe are inserted in place, then Chef continues in the including recipe.

Chef一旦拥有我处理了所有食谱的所有资源,然后遍历资源集合,并按照添加到集合的顺序对每个食谱执行指定的操作。

Once Chef has processed all the recipes for all their resources, it walks the resource collection taking the specified action on each in the order it was added to the collection.

我强烈建议阅读有关此过程的文档。它适用于Solo主厨;仅跳过从服务器下载食谱的部分。

I highly recommend reading the documentation on this process. It applies to Chef Solo; only the part where the cookbooks are downloaded from the server is skipped.

  • https://docs.chef.io/chef_client.html#the-chef-client-run

要确保仅测试您要测试的配方,请通过JSON文件将其包括在节点的运行列表中。看起来像这样:

To ensure that only the recipes that you want to test are tested, include them in the node's run list via a JSON file. It looks like this:

{ "run_list": ["recipe[mything]", "recipe[anotherthing]"] }

运行列表只是一个数组,项目可以为 recipe [cookbookname ] role [somerole] 。您可以在Chef Solo文档上阅读有关如何在Chef Solo中使用角色的更多信息。

The run list is just an array, and items can be recipe[cookbookname] or role[somerole]. You can read more about how to use Roles with Chef Solo on the Chef Solo documentation.

  • https://docs.chef.io/chef_solo.html

如果在Chef加载食谱组件(每个食谱中的ruby文件)时进行了系统更改,则您做错了(tm)并应重构这些操作以在从食谱中调用的资源。

If you have system changes being made when Chef is loading the cookbook components (the ruby files in each cookbook), then "You're Doing It Wrong"(tm) and should refactor those things to be done in a resource called from a recipe.

这篇关于指定要与Chef Solo一起运行的食谱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆