Thursday, November 22, 2012

Puppet run_list (like Chef)

Chef has a very nice concept where whatever you need to run is part of a run_list. run_list. This provides an enforced way to run it as opposite to let control of the execution to the configuration management framework. Puppet lacks such run list - can use operators as -> but there is no global list. This trick can simulate a run_list with the same results. Create a file called test.pp with the content:
class one() {
    notice('class one')
}

class two() {
    notice('class two')
}

class three() {
    notice('class three')
}

define include_list  {
    $cls = $name
    notice("including $name")
    include $name
}

if $fqdn == 'debian.localdomain'{
    $clss = ['one', 'two', 'three']
    include_list { $clss:; }
}
And then run it as
 puppet apply test.pp
 notice: Scope(Include_list[one]): including one
notice: Scope(Class[One]): class one
notice: Scope(Include_list[two]): including two
notice: Scope(Class[Two]): class two
notice: Scope(Include_list[three]): including three
notice: Scope(Class[Three]): class three
notice: Finished catalog run in 0.04 seconds