【发布时间】:2016-02-24 10:13:07
【问题描述】:
我有 LWRP,它应该在其 create 操作中创建 cookbook_file
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
当我从 create 方法中删除 cookbook_file 时,日志正确显示:INFO: vu:@new_resource.vu_name-text.txt
在下一步中,我替换了
source "#{@new_resource.vu_name}"
与测试配方中指定的值相同
source "text.txt"
并且文件被提取。
在我看来,cookbook_file 内部 ruby 块没有得到new_resource 的副本,它变成了nil。
如何使用 LWRP 的属性作为在 action 中声明的资源的参数?
【问题讨论】:
-
根据您的语法,您使用的是 chef 12.5+ 自定义资源,只需按照 the doc here 删除
@new_resource部分 -
就是这样。虽然我读了那个文件,但我还是错过了 :-)
标签: ruby chef-infra lwrp