Thursday, December 18, 2014

Puppet - Containment Again

Most of the content is a poor regurgitation of these pretty damn good links:
http://blog.mayflower.de/4573-The-Puppet-Anchor-Pattern-in-Practice.html
http://bombasticmonkey.com/2011/12/27/stop-writing-puppet-modules-that-suck/

include does NOT cause the included class to be Contained within the including class
require -does- .....

When you write a module, make sure you CONTAIN ALL THE THINGS.
Otherwise you may screw a user of your module... as your classes 'float off' and may not be applied when the user anticipated.

Your containing class could use a buncha REQUIREs to contain other classes, BUT
if you need to declare parameterized classes, you are SOL or 
if you need the classes you declare in a certain sequence, you'll have to use another option:


You'll either need "The Anchor Pattern" or "Contain" (contain is only available in 3.4+)
-------------------------------------
"Anchor Pattern" example:
class wrapper {
  anchor { 'wrapper::begin': } ->
  class { 'foo': }             ->
  class { 'bar': }             ->
  class { 'end': }             ->
  anchor { 'wrapper::end': }
}
-------------------------------------
"Contain" Example:
class wrapper {
  contain foo
  contain bar
  contain end

  Class['foo'] ->
  Class['bar'] ->
  Class['end']
}
-------------------------------------

No comments:

Post a Comment