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
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?
Code below tells us to install new_resourse if it has different path attribute?
@current_resource = Chef::Resource::Directory.new(@new_resource.name)
if ::File.exists?(@current_resource.path) && @action !=
Main confusion i experience when i’m analyzing those 2 strings of code :
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
@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.