Any class that is declared via an include within another class may have their resources applied outside of the class from which they were declared.
Using your example from above, which I assume comes from here, let's break it down.
Personally, I think the documented example should be broken out into two different code blocks. As it reads, it appears it's as one, but it's really not, so I've separated them here for clarity. Let's start with the include behavior:
class ntp {
file { '/etc/ntp.conf':
...
require => Package['ntp'],
notify => Class['ntp::service'],
}
include ntp::service
package { 'ntp':
...
}
}
If we were to declare class ntp
somewhere, as in the given docs example, like this:
include ntp
exec { '/usr/local/bin/update_custom_timestamps.sh':
require => Class['ntp'],
}
the exec would happen after the file 'etc/ntp.conf' and the package 'ntp', but wouldn’t necessarily happen after the service. This is because resources declared within a class are always invoked within the surrounding class that declared them (in this case the surrounding class is the ntp class), but declared classes (IE ntp::service), and the resources within those declared classes MAY NOT be invoked before the surrounding class ends.
If resources declared inside a class (IE ntp::service) need to be guaranteed invoked within the surrounding class that declares it (IE ntp), then contain must be used. Then we'll ensure that the exec will happen after all the resources in both class ntp and class ntp::service. Why? Because ntp::service
was contained.
You may need to read, and reread it over and over before it starts to sink in (as I have). contain, as I understand, was made as a replacement to the anchor pattern. Here is a youtube video that explains how resources declared within a class_a that are declared inside class_b via an include class_a
can float off on their outside outside of the surrounding class.
If you don't get it right away, don't worry. This is a bit of an advanced topic for Puppet and it'll eventually gel.
Hope that helps!
--
Kris