Question

I'm writing a LWRP for chef 10. And when that resource is run in other recipes it should be marked as "updated_by_last_action" if something has changed. But if nothing has changed. updated_by_last_action should be false.

So as example I have chef documentation http://docs.opscode.com/lwrp_custom_provider.html#updated-by-last-action. That example the resource template is wrapped inside an variable to test if it's been changed, and then set the updated_by_last_action status. So my code should look something like this

f = file new_resource.filename do
xxx
end
new_resource.updated_by_last_action(f.updated_by_last_action?)

t = template new_resource.templatename do
xxx
end
new_resource.updated_by_last_action(t.updated_by_last_action?)

m mount new_resource.mountpoint do
xxx
end
new_resource.updated_by_last_action(m.updated_by_last_action?)

But if a provider gets bigger and uses a lot of resources like template, file, directory, mount, etc.. Should all those resource be wrapped inside variables like the example to find out if a resource have been updated, so to then further send a status that this provider have been updated.

I'm wondering if there is a simpler and cleaner way to run new_resource.updated_by_last_action(true) other then to wrap all resources inside variables. Cause if I just put a new_resource.updated_by_last_action(true) inside action before end the LWRP is marked as being updated every chef run, which is not optimal.

Was it helpful?

Solution

You can add use_inline_resources at the top of your LWRP, which delegates the updated_by_last_action to the inline resources.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top