Puppet Manifest Example: Defining Order Between Actions

Last updated:

Since Puppet resources are run in no particular order, we must explicitly define temporal dependencies between them.

In order words, if we want a given command to be run only after another command has run, we must declare it using keywords such as require, before, notify and subscribe.

Twitter Linkedin YC Hacker News Reddit

For example, making sure a system update is run before we try to install the git package.

# tell puppet what to prepend to commands
Exec { 
    path => [ "/bin/", "/sbin/" , "/usr/bin/", "/usr/sbin/" ]
}  
# a command to run system updates
exec { 'sys_update':
    command => "apt-get update --fix-missing"
}  
class git {
    package{'git-core':
        ensure => 'installed',
        require => Exec['sys_update']
    }
}  
include git

All keywords

  • before => Resource['foo']: current resource will always be applied before Resource 'foo'.
  • notify => Resource['foo']: current resource will always be applied before Resource 'foo', and resource 'foo' will be notified (i.e. re-run) every time the state of the current resource changes.
  • subscribe => Resource['foo']: the current resource will always be applied after Resource 'foo'. The current resource will be re-applied whenever Resource 'foo' changes state.

Using Arrows instead of keywords

TODO: example
TODO: note that requiring a resource with arrows to others **does not** trigger the other resources.

Dialogue & Discussion