chef-infra - 是否可以在 shef(chef shell)客户端模式下强制加载 run_list

标签 chef-infra chef-recipe

在调试 Chef Recipe 中的错误时,我通常喜欢登录到有问题的机器上,输入“shef -z”。如果之前有一次成功运行,注册的 run_list 会自动加载所有相关属性和配方,这样我就可以直接跳进去尝试有问题​​的行。

问题是,如果 chef-client 在第一次运行时失败,run_list 是空的,shef 甚至会从缓存中删除(非常需要的) Recipe ,说“此客户端不再需要它的 Recipe ”。有没有办法强制 shef 让我使用我的 run_list?

官方维基mentions:

"The run list will be set in the same way as normal chef client runs."

但尝试“-j”似乎没有帮助。

我也尝试运行单人模式(“-s -j”),如本 blog post 中所述.它加载 run_list(不扩展它,这很奇怪),但是当我尝试做任何事情时,我得到如下内容:

"Cookbook tomcat not found. If you're loading tomcat from another cookbook, make sure you configure the dependency in your metadata".

请注意,我的配方有几十个 3 层深的依赖关系,因此手动将所有代码粘贴到 shef 并不是一个真正的选择。我目前的解决方法是上传一个修改过的 Recipe ,其中所有可能有问题的部分都被注释掉了(然后从那里手动继续),但我希望有一个更好的选择。

最佳答案

当您在客户端或单机模式下启动 shef 时,默认情况下不包含 Recipe ,因为 shef 的一个用例是确定为什么 Recipe 可能根本没有加载,例如导致某些异常的编译时错误.

因此,您需要使用 include_recipe 来包含您希望使用的 Recipe 。您可以为节点运行列表中的所有角色/配方自动执行此操作:

node.run_list.expand(node.chef_environment).recipes.each do |r|
  include_recipe r
end

有关这方面的更多信息,以及使用 Shef 调试 chef-client 运行的一系列其他重要技巧,请参阅 Steven Danna's blog post

关于chef-infra - 是否可以在 shef(chef shell)客户端模式下强制加载 run_list,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12843144/

相关文章:

mysql - Chef mysql opscode-cookbooks 不工作 : "could not find recipe ruby for cookbook mysql"

mysql - Chef Recipe 将值添加到 mysql 表

python - 在 Chef Recipe 中执行requirements.txt文件来安装python模块的正确方法是什么?

ruby - 无法将菜谱从 Knife 上传到 Chef 服务器

chef-infra - 我可以在配方中标记节点吗?

linux - 如何防范最后一个区 block 运行的 Chef -客户状态;不要使用状态文件

chef-infra - 在 Chef Recipe 中,如何根据角色分配 erb 模板

ruby - Chef 条件资源参数

ruby - 使用 Rspec 断言 Ruby(Chef Recipe)中方法的返回值

docker - 使用 Chef 设置 apt 存储库