随着一些默认的厨师资源,也可以访问他们的一些属性,它们被称为后
# recipes/default.rb
f = file "/tmp/file_resource" do
owner "root"
group "root"
mode "0755"
action :create
end
log "Path to my file is #{f.path}" # outputs "/tmp/file_resource"
这怎么能在一个自定义LWRP来实现(在这里就是一个例子)
# resources/default.rb
actions :create
default_action :create
attribute :relative_path, :kind_of => String, :name_attribute => true
attribute :full_path, :kind_of => String
在此提供程序,我试图更新的属性new_resource.full_path
等于文件资源的路径
# providers/default.rb
action :create do
f = file "/path/to/my/resource/#{new_resource.relative_path}" do
owner "root"
group "root"
mode "0755"
action :create
end
new_resource.full_path(f.path)
new_resource.updated_by_last_action(f.updated_by_last_action?)
end
然而,当我尝试访问resource.full_path
在配方,它是nil
,而不是预期的/path/to/my/resource/relative/path
# recipes/default.rb
resource = my_awesome_lwrp "relative/path" do
action :create
end
log "Full path for my resource: #{resource.full_path}" # outputs "Full path for my resource:"
这个例子是虚构的,我知道,现实世界的应用程序/原因可以在默认的资源/供应商在这里可以看到https://github.com/peterjmit/chef-ssl-cert