It is possible to create a class that only executes when receives a notification event? I want to do exactly what “exec” does with “refreshonly”, I could not find how to do this. Specifically, what I want to do is:
I have an archive resource, that downloads a file, with a “create” attribute:
It is possible to create a class that only executes when receives a notification event?
No. And for that reason, it is best to avoid conceptualizing Exec resources as behaving as you describe. Every resource declared in a node’s catalog is synced with the node on each run, except inasmuch as a resource failure may prevent other resources from being synced, according to established relationships. Resources that are successfully synced and that also receive an event from another resource are also refreshed, though for many resource types, the refresh action is a no-op.
There are no exceptions, or at least it is comfortable and consistent to conceptualize Puppet’s behavior that way. To that end, we can reconcile the effect of refreshonly => true on an Exec resource by interpreting it as declaring unconditionally that the resource is initially in sync, instead of whether it is initially in sync being determined in accordance with its onlyif, unless, and creates parameters (and defaulting to “no”). Since such an Exec is already in sync at the start of a run, syncing it does not involve taking any action. Classes have no analogous feature.
As for what you are trying to achieve, I recommend a combination of declaring Exec resources belonging to the class as being refreshonly (which might be conveniently achieved by declaring that as a resource default) and allowing other resources to sync.