Reputation: 199
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?
Upvotes: 4
Views: 24846
Reputation: 8223
Either variant works equally fine. They have some concrete uses though.
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.
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
include
statements for the same classUpvotes: 5