【发布时间】:2015-04-24 21:23:23
【问题描述】:
我使用 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 添加到资源定义中。但我从未将其视为任何文档中的要求。从文档中,我假设 Chef 在资源/提供程序编译期间负责在任何属性上设置 attr_accessor。谁能确认我的发现或解释真正发生的事情?
谢谢。
【问题讨论】:
标签: chef-infra lwrp