我有 LWRP 应该cookbook_file
在其create
操作中创建
resource_name :vuy
property :vu_name, String, name_property :true
actions :create
action :create do
log "vuy:@new_resource.vu_name-#{@new_resource.vu_name}"
cookbook_file "c:/temp/test.xml" do
source "#{@new_resource.vu_name}"
end
end
和测试配方
vuy 'text.txt'
chef-client
执行失败并出现错误NoMethodError: undefined method 'vu_name' for nil:NilClass
当我cookbook_file
从create
方法中删除时,日志正确显示:INFO: vu:@new_resource.vu_name-text.txt
在下一步中,我替换了
source "#{@new_resource.vu_name}"
与测试配方中指定的值相同
source "text.txt"
并获取了文件。对我来说,看起来cookbook_file
内部 ruby 块没有得到副本,new_resource
它变成nil
.
如何使用 LWRP 的属性作为在动作中声明的资源的参数?