Ordering puppet resources with run stages
I've found that I need certain resources, like yum repositories or AD authentication, to be set up on a new host before many other resources can be configured on a Linux host. Enter Puppet run Stages.
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 you don't explicitly assign a puppet class to a stage, then it will be in the main stage.
In the above example, I've created a custom stage called stage01
and assigned classes to it. As you can see, stage01
is fired before stage main
. The ->
chaining arrows also ensure ordering. So, the three classes within stage01
are run in a specific order. As an alternative, I could have specified three different run stages for each class, but I prefer grouping all three into a run stage, for scalability.
Then apply the runstages::standard
class to your hosts via your External Node Classifier (ENC) e.g. Foreman, if you use one, or in your site manifest. With Foreman, I had to remove the puppet classes yumrepos
, authentication
, and hosts
from my hostgroup(s) otherwise you'll get duplicate declaration warnings.