我使用 chefdk 创建了一个 LWRP,并遵循文档和一些博客文章。
资源
actions :install
default_action :install
provides :foo
attribute :name, :kind_of => String, :name_attribute => true
提供者
provides :foo
def whyrun_supported?
true
end
use_inline_resources
action :install do
converge_by("install: #{@new_resource}") do
execute "installation of: #{@new_resource.name}" do
command "foo install #{@new_resource.name}"
end
end
end
def load_current_resource
@current_resource = Chef::Resource::Foo.new @new_resource.name
@current_resource.name = @new_resource.name
end
在食谱中使用此 LWRP 时,我会收到以下错误:
undefined method `name=' for Chef::Resource::Foo
我可以修复它的唯一方法是添加attr_accessor :name
资源定义。但我从未将其视为任何文档中的要求。从文档中,我假设 Chefattr_accessor
在资源/提供者编译期间负责设置任何属性。谁能确认我的发现或解释到底发生了什么?
谢谢。