我有一本my_service带有自定义资源的食谱write_config。该资源是从另一本食谱中调用的node_a。
my_service/resources/write_config.rb:property :template_source, String, name_property: true property :calling_cookbook, String, required: true action :create do template "/tmp/test.txt" do source template_source cookbook calling_cookbook owner 'root' mode '0644' action :create end end节点食谱食谱
node_a/default.rb:my_service_write_config 'config.erb' do calling_cookbook 'node_a' end
这工作正常,但我想摆脱calling_cookbook财产。
有没有办法自动获取calling_cookbook名称?
解决方案
(谢谢coderanger!)基本资源template似乎在调用 ( node_a) 食谱 (?) 的上下文中得到评估。
my_service/resources/write_config.rb:property :template_source, String, name_property: true action :create do template "/tmp/test.txt" do source template_source owner 'root' mode '0644' action :create end end在节点食谱食谱中使用它
node_a/default.rb成为单行:... include_recipe 'my_service' my_service_write_config 'config.erb' ...
整洁的!