食谱之间的共享文件/模板

gdu*_*ham 11 automation chef

我们有多本参考相同文件和模板的食谱,想知道是否有合理的方法来确保所有这些都是相同的文件,以确保没有过时。是否可以有多个食谱/食谱引用的单个文件/模板?我考虑过使用符号链接,但是这对我们不起作用,因为 Git 不支持它们。

jti*_*man 17

Cookbook_file 和模板资源支持“cookbook”参数,该参数指定哪本食谱包含源文件。然后您可以创建一个“公共”食谱,其中这些文件作为单个实体存在。例如:

% cookbooks/commons
cookbooks/commons
|-- files
|   `-- default
|       `-- master.conf
`-- templates
    `-- default
        `-- general.conf.erb
Run Code Online (Sandbox Code Playgroud)

假设您有两本食谱,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
Run Code Online (Sandbox Code Playgroud)

但是,我会问为什么您的食谱中不同类型的功能之间存在重复?也就是说,这种东西是否适合您使用的自定义轻量级资源/提供程序?