Puppet [SOLVED]: How to create a class that only refresh in Puppet

Puppet [SOLVED]: How to create a class that only refresh in Puppet

Home Forums Automation Tools Puppet Puppet [SOLVED]: How to create a class that only refresh in Puppet

Tagged: 

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #225769

    Cloudy Point
    Keymaster

    QuestionQuestion

    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:

    archive { "/opt/service/service-${version}.jar":
        source        => "http://[ARTIFACT_URL]/service-${version}.jar",
        creates       => "/opt/service/service-${version}.jar",
        cleanup       => false,
    }
    

    I would like to do this:

    Archive["/opt/service/service-${version}.jar"] ~> Some_custom_class['some_title']
    

    But “Some_custom_class” can only execute when the archive downloads the file, that is when a notification event is triggered.

    Thanks!

    #225770

    Cloudy Point
    Keymaster

    Accepted AnswerAnswer

    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.

    Source: https://stackoverflow.com/questions/47356016/how-to-create-a-class-that-only-refresh-in-puppet
    Author: John Bollinger
    Creative Commons License
    This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.