I think that I am almost at the understanding that I need in regards to
LWRPs and notifications and use_inline_resources - I just want to verify
that I truly get this subject given what I think is it's importance and the
somewhat fuzzy docs that seems to exist around it.
I write a good number of LWRPs and originally used the below general
paradigm as I learned from the customizing chef o'reilly book.
def whyrun_supported?
true
end
action :create do
_user = new_resource.user ? new_resource.user : "root"
_group = new_resource.group ? new_resource.group : "root"
directory ::File.dirname(new_resource.name) do
owner _user
group _group
mode "0700"
action :create
recursive true
end
new_resource.updated_by_last_action(true)
end
I realized soon that there is a a serious flaw to this original paradigm
which is that by specifying new_resource.updated_by_last_action(true) this
resource always thinks that it does something and if I happen to perform
any notification based on it - they will always fire. (Took a a bit of time
to figure out why a service was restarting on every Chef run)
I use Chef 11 all around so I realized that I could change my overall
paradigm to
def whyrun_supported?
true
end
use_inline_resources
action :create do
_user = new_resource.user ? new_resource.user : "root"
_group = new_resource.group ? new_resource.group : "root"
directory ::File.dirname(new_resource.name) do
owner _user
group _group
mode "0700"
action :create
recursive true
end
end
Now I get the behavior that I want which is that when the underlying
resource actually triggers then the LWRP will send notifies rather than all
the time. I realize that the use of use_inline_resources means that I can
only notify other resources within my LWRP - but that is fine by me.
MY FIRST REAL QUESTION: If I happen to only use already existing resources
in my then I never have call new_resource.updated_by_last_action(true). Is
this accurate?
SECOND QUESTION: If I need to call new_resource.updated_by_last_action(true)
because I do something outside and existing resource -- can I mix
use_inline_resources and new_resource.updated_by_last_action(true) in the
same provider?
THIRD QUESTION: I have seen the below code which I know is "old" but I
think should work but does not seem to work. Is this paradigm now longer
valid? Even when the resource creates the directory it seems
that d.updated_by_last_action? always evaluates to false
def whyrun_supported?
true
end
action :create do
_user = new_resource.user ? new_resource.user : "root"
_group = new_resource.group ? new_resource.group : "root"
d = directory ::File.dirname(new_resource.name) do
owner _user
group _group
mode "0700"
action :create
recursive true
end
new_resource.updated_by_last_action(d.updated_by_last_action?)
end
Thanks for listening.