我试图find一种方法来dynamic地应用模板资源在食谱模板文件夹内的文件夹中的所有文件。 就像是:
Dir.foreach("../templates/default/shared/") do | file | # This is the wrong line... template "/home/admin/shared/#{file}" do source "shared/#{file}" … end end
我该怎么做? 我试图避免有一个单独的目录中的所有文件列表作为variables…谢谢。
您的代码将在节点的上下文中执行,因此您的Ruby代码( Dir.foreach )将需要检查节点的本地caching。 在我的厨师安装中,我的厨师 – 客户端configuration模板需要本地cachingpath,所以我有这个属性: node[:chef][:cache_path] 。
所以:
Dir.foreach("#{node[:chef][:cache_path]}/cookbooks/the_cookbook/templates/default/shared/")
编辑:在现代厨师configuration,模板将不存在服务器上,直到他们需要。 你需要添加到你的client.rb :
no_lazy_load true