chef-infra - 如何让包装器说明书在定义中使用其父级模板?

标签 chef-infra chef-recipe cookbook

我正在使用 apache2 供应商 Recipe 和我自己的应用程序 Recipe 。在我的配方中,我想使用网站的 web_app 定义,并让它使用供应商说明书中定义的模板

#my-apache2/recipes/my-site.rb

web_app "my-site" do
    #template not specified here, so it should use default
    server_name "my-site.com"
    docroot "#{app_dir}/public"
end

结果

Error executing action `create` on resource 'template[/etc/httpd/sites-available/my-site.conf]'
================================================================================

Chef::Exceptions::FileNotFound
------------------------------
Cookbook 'my-apache2' (1.0.0) does not contain a file at any of these locations:

因为它正在查找 my-site 说明书,而不是 apache2 templates 目录。

我尝试了对其他资源有效的方法:

resources("template[web_app.conf.erb]").cookbook "my-apache2"

但是这个路径是根据资源参数(name)动态生成的。

#apache2/definitions/web_app.rb

application_name = params[:name] 
template "#{node['apache']['dir']}/sites-available/#{application_name}.conf" do
    source   params[:template]
...

所以它返回这返回错误

Chef::Exceptions::ResourceNotFound
----------------------------------
Cannot find a resource matching template[web_app.conf.erb] (did you define it first?)

有没有办法让它使用供应商 Recipe 的模板,而不将其复制到我的包装 Recipe 中?

最佳答案

查看定义来源: https://github.com/onehealth-cookbooks/apache2/blob/45f08b4060f23573dbec65be32bf25baee56b734/definitions/web_app.rb#L35

如果您向定义提供说明书参数,那么它将在您指定的任何说明书中查找模板文件。 (在这种情况下,听起来您想指定 apache2)

web_app "my-site" do
  server_name "my-site.com"
  docroot "#{app_dir}/public"
  cookbook 'apache2'
end

关于chef-infra - 如何让包装器说明书在定义中使用其父级模板?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23794787/

相关文章:

api - 以编程方式获取 Chef 独奏菜谱中的 Vagrant 属性

ruby - 解析运行列表的 Recipe 时出错 : missing cookbooks: No such Cookbooks

chef-infra - Chef Recipe 中的属性优先级

chef-infra - 无法使用knife命令删除节点属性

centos - 是什么导致此错误错误:#<Chef::Recipe:0x00000003ca0870> 的未定义方法 `mysql_service'?

mysql - 使用 Ruby/Chef Recipe for Vagrant 导入 Mysql 数据库

chef-infra - 覆盖 Chef 运行列表但继续使用节点属性

shell - 捕获shell输出时Chef编译错误

chef-infra - Chef模板中的节点名称?

mysql - Chef MySQL Recipe 用户创建错误