Question

Okay, I just started learning Puppet and working through the docs. From what I see:

  • require does the same as before
  • subscribe does the same as notify

Obviously these are added at opposite sides of the dependency relationship, but you get my point.

From a code readability and maintainability aspect, is using one (of each pair) better than the other? Should I use both for maximum clarity or would this make the maintenance cumbersome? Thoughts?

Was it helpful?

Solution

Either variant works equally fine. They have some concrete uses though.

  • Make intentions more clear

E.g.

exec { "initialize-footool": require => Package["footool"] }
file { "/etc/default/footool": before => Exec["initialize-footool"] }

read more like english than just requires on the exec.

  • Build relations to other resources that don't know about the resource in question

E.g.

include apache
exec { "apache2ctl graceful": require => Package[apache] } # package inside class apache

The latter is pretty bad practice though. I found that one of the most definite benefits lie in these metaparameters' ability to target whole classes instead.

include apache
exec { "apache2ctl graceful": require => Class["apache"] }
file { "/etc/default/apache2": before => Class["apache"] }

People who are intent on limiting themselves to, say, require instead of ever using before can resort to this syntax

class { "apache": require => File["/etc/default/apache2"] }

The community discourages class {} style declarations though, because

  • it cannot be used to declare the same class more than once
  • it imposes parse order issues even when mixed with include statements for the same class
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top