- From: <
>
- To:
- Subject: [chef] LWRP load_current_resourse questions
- Date: Fri, 31 Jan 2014 00:14:38 -0800 (PST)
Greetings!
In the LWRP Chef docs regarding provider DSL, i saw load_current_resourse
method, which i can’t fully understand.
I would like to terminate that lack of knowledge and i would appreciate any
help in this.
It’s description from official docs :
The load_current_resource method is used to find a resource on a node based on
a collection of attributes. These attributes are defined in a lightweight
resource and are loaded by the chef-client when processing a recipe during a
chef-client run. This method will ask the chef-client to look on the node to
see if a resource exists with specific matching attributes.
But what it actually does when it finds matching resource on a node or can’t
find it?
My guess :
load_current_resourse is processed by provider when it compiled new_resource
object it simply just tries to find
installed resource on a node matching compiled object? If it can find it it,
it
does nothing, otherwise it installs compiled object?
I’m not quite sure how it process load_current_resourse when i saw this 2
examples from chef repository.
Code below tells us to install new_resource every time?
#ruby_block provider
def load_current_resource
true
end
Code below tells us to install new_resourse if it has different path
attribute?
#directory provider
def load_current_resource
@current_resource = Chef::Resource::Directory.new(@new_resource.name)
@current_resource.path(@new_resource.path)
if ::File.exists?(@current_resource.path) && @action !=
:create_if_missing
load_resource_attributes_from_file(@current_resource)
end
@current_resource
end
Main confusion i experience when i’m analyzing those 2 strings of code :
@current_resource =
Chef::Resource::SomeUndeclaredClass.new(@new_resource.name) # It creates
object
of class “SomeUndeclaredClass” passing to it new_resource.name attribute
and assigns object to current_resourse instance variable? Also as i understood
when initializing new resource class i can use any name instead of
SomeUndeclaredClass place?
@current_resource.path(@new_resource.path) # it just assigns
new_resourse.path to current_resourse.path attribute?
And if load_current_resource method successfully found matching resource on a
node it does nothing,otherwise it installes new compiled resource?
That is a list of questions i would like to resolve and i would appreciate any
help with that.
Best Regards.
- [chef] LWRP load_current_resourse questions, anikeev1988, 01/31/2014
Archive powered by MHonArc 2.6.16.