我正在使用 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 中?
最佳答案
如果您向定义提供说明书参数,那么它将在您指定的任何说明书中查找模板文件。 (在这种情况下,听起来您想指定 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/