Answers:
cookbook_file和模板资源支持“ cookbook”参数,该参数指定哪个食谱包含源文件。然后,您可以创建一个“公共”食谱,其中这些文件作为单个实体存在。例如:
% cookbooks/commons
cookbooks/commons
|-- files
| `-- default
| `-- master.conf
`-- templates
`-- default
`-- general.conf.erb
假设您有两个食谱,thing1和thing2,并且它们都使用它们。配方可能是:
# thing1/recipes/default.rb
cookbook_file "/etc/thing1/master.conf" do
source "master.conf"
cookbook "commons"
end
template "/etc/thing1/general.conf" do
source "general.conf.erb"
cookbook "commons"
end
# thing2/recipes/default.rb
cookbook_file "/etc/thing2/like_master_but_different.conf" do
source "master.conf"
cookbook "commons"
end
template "/etc/thing2/not_as_general_as_you_think.conf" do
source "general.conf.erb"
cookbook "commons"
end
但是,我想问一下,为什么您的食谱中的各种功能之间存在重复?也就是说,这种东西是否适合您使用的自定义轻量级资源/提供程序?