On 6/4/18 8:25 AM, Peter Berghold wrote:
I was looking at someone else's code one day last week and saw a pattern I've not seen before. Maybe that's what I get for developing Puppet code in a vacuum. :-)

class someclass (
     $parm1 = $::someclass::params::parm1,
     $parm2 = $::someclass::params::parm2       # so far I get it.
) inherits someclass::params {             # ok, I get it

      class{'someclass::package': }        # OK
      -> class('someclass::configure':}    # right...
      -> Class{'someclass':}                    #  HUH?  What does that do?
}

Is that last step necessary and why?


The last step was fairly common in Puppet 2.7 code before Anchors. It is necessary if you want to do something like this.

class profile::mystack {

  include ::otherclass
  include ::someclass

  Class['someclass'] -> Class['otherclass']
}

By adding that -> Class{'someclass':} to the end you create a chain that requires all classes to completed before 'someclass' is completed. Allows you to do the ordering I've shown.

In Puppet 3.4 the keyword 'contain' was introduced. The modern implementation might look like

class someclass (
    $parm1 = $::someclass::params::parm1,
    $parm2 = $::someclass::params::parm2,
) inherits someclass::params {

  contain someclass::package
  contain someclass::configure

  Class['someclass::package']
  -> Class['someclass::configure']
}

fwiw a lot of my modules internally will mix and match include with contain. In the case below I do not want containment around the yum repo because in our system that's guaranteed to cause dependency cycles. Also service usually encapsulate some systemd reloading which can cause the same problem. Containing install and config is usually enough to allow other modules to depend on my somedaemon module though not always.

class somedaemon {

  include ::somedaemon::repo
  contain ::somedaemon::install
  contain ::somedaemon::config
  include ::somedaemon::service

  Class['::yum']
  -> class['::somedaemon::install']
  -> Class['::somedaemon::config']
  ~> Class['::somedaemon::service']
}

Ramin

--
You received this message because you are subscribed to the Google Groups "Puppet 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to puppet-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/e5e15946-72ca-2cc8-e7e3-e40489d98019%40badapple.net.
For more options, visit https://groups.google.com/d/optout.

Reply via email to