I am working on what I’ll call an aggregate LWRP: it aggregates a number of
subresources so that they can be treated as one. In my example the provider
installs a package, creates a directory, and builds a couple of config
files from templates, by using the resource DSL in the provider’s action
method. However I’m struggling to get notifications from the aggregate
resource working. It seems like this would be a common pattern, but I
haven’t found any examples that deal with the notification problem. I’ve
tried a few different approaches:
- In the action method of my provider, adding the subresources to an
array, then iterating over the subresources’ updated? methods at the end of
the action method to determine whether or not to call
new_resource.updated_by_last_action(true). - Same as number 1, but iterating in a ruby_block which is the final
subresource, to defer the updated? checks from compile time to execution
time. - Defining a ruby_block subresource with action :nothing, and sending
it a :create notification from the subresources, then relying on the
ruby_block to call new_resource.updated_by_last_action(true).
None of these approaches result in subscribers to the aggregate resource
being notified when a subresource is updated. This has left me with the
following questions:
- Is there an example of such an aggregate resource and its provider
that someone could point me to? - Is there a better way to accomplish my goal (notification when any of
a group of resources is updated, without the subscriber having to know
about each of the grouped resources)? - Does this comment on line 67 of provider.rb (Chef 0.10.8) explain why
notifications don’t seem to escape my aggregate resource: “…resources
within this block cannot interact with resources outside, e.g.,
manipulating notifies”, and if so, how can I get around this limitation?
Thanks,
Kevin Christen