Ordering puppet resources with run stages

As of version 2.6, Puppet introduced a feature called “Run Stages” that will allow to better control the order that Puppet configures your system. Run stages are an additional way to order resources. Groups of classes run before or after everything else, without having to explicitly create relationships with other classes. The run stage feature has two parts: a stage resource type, and a stage meta parameter, which assigns a class to a named run stage.


class runstages::standard {

    # declare additional run stage

    stage { 'stage01': }

    Stage['stage01'] -> Stage['main']


    # assign classes to stages

    class { 'yumrepos':

      stage => 'stage01',

    }->

    class {'authentication':  # Active Directory auth setup

      stage => 'stage01',

    }->

    class {'hosts':  # hosts file

      stage => 'stage01',

    }

}

Stage['main'] is the default run stage. If we don't explicitly assign a puppet class to a stage, then it will be in the main stage.

In the above example, created a custom stage called stage01 and assigned classes to it. As we can see, stage01 is fired before the stage main. The -> chaining arrows also ensure ordering. So, the three classes within the stage01 are run in a specific order. As an alternative, we could have specified three different run stages for each class, but we prefer grouping all three into a run stage, for scalability.

Then apply the runstages::standard class to our hosts via our External Node Classifier (ENC) e.g. Foreman, if we use one, or in our site manifest. With Foreman, I had to remove the puppet classes yum repo, authentication, and hosts from my host group(s) otherwise you'll get duplicate declaration warnings.

Relevant Blogs:

Puppet Multi-master 

Puppet Container Registry 

Chef data bags  

Kubernetes Hardway

Recent Comments

No comments

Leave a Comment