【问题标题】:Using files with wrapper cookbook and recipes defined in parent cookbook将文件与父食谱中定义的包装食谱和食谱一起使用
【发布时间】:2023-04-05 23:39:01
【问题描述】:

我的厨师跑步最近抛出了这个错误:

Chef Client failed. 22 resources updated in 90.306407696 seconds
[2014-12-19T19:47:24+00:00] ERROR: cookbook_file[/srv/mycookbook/static/a.png] (mycookbook::_deploy line 82) had an error: Chef::Exceptions::FileNotFound: Cookbook 'mycookbook' (0.4.5) does not contain a file at any of these locations:
  files/ubuntu-12.04/static/a.png
  files/ubuntu/static/a.png
  files/default/static/a.png

This cookbook _does_ contain: ['a.css','b.html','c.html']

那是因为主要食谱 mycookbook(我不拥有)有以下几行:

node['myattributes']['theme']['static_files'].each do |file|
  cookbook_file node['myattributes']['install_dir'] + "/static/" + file do
    source "static/#{file}"
    owner node['myattributes']['user']
    group node['myattributes']['group']
    cookbook node['myattributes']['theme']['source_cookbook']
  end
end

但我的孩子或使用 mycookbook 的包装食谱有这些具有不同属性的行并且失败了:

override['myattributes']['theme']['compile_files'] = ['a.html']
override['myattributes']['theme']['static_files'] = ['a.png']

我将这些文件存储在我的包装食谱 files/default/static/files/default/etc/

我已经知道问题所在了。我的包装食谱没有mycookbook 期望的一些文件,但我为什么会这样呢?无论如何,这些属性都应该被覆盖。

我的问题是有更好的方法来处理在files/default 下检查的文件,即配方定义是在父说明书中定义的,而包装说明书只是用不同的文件定义不同的属性集?

【问题讨论】:

    标签: chef-infra chef-recipe cookbook


    【解决方案1】:

    您需要将 node['myattributes']['theme']['source_cookbook'] 设置为 `then 包装器食谱的名称,以便它在正确的食谱中查找。

    【讨论】:

    • 谢谢!这似乎行得通!请问使用cookbook_file资源是否是个好主意?因为我不确定原作者为什么这样做,但我认为在构建库助手时这样做会更好。
    • 不确定您还会使用什么,cookbook_file 是将文件从食谱复制到文件系统的唯一方法。至于制作配方与可扩展资源以更好地应对此类事情,我想我可以自信地说我属于后者,因为我发明了很多。
    • 这对我来说是最简单的方法(在gerrit cookbook 中让包装器食谱为 Gerrit 主题提供文件。我明白了这一点,gerrit_theme_file LWRP 会让事情变得更容易一些。 (但由于时间不够,我对食谱的状态总体上不满意)。但最后,文件必须通过remote_filecookbook_file 部署(作为template 资源到你的资源) re 可能更习惯于不适用于二进制文件(图像)。
    最近更新 更多