A quick rundown of what we've learned in this chapter.
Anything you can do on the command line, Puppet can do with an exec
resource. Specify the command to run using the command
attribute:
exec { 'Run my arbitrary command': command => '/bin/echo I ran this command on `/bin/date` >/tmp/command.output.txt', }
By default, an exec
resource will always be applied, every time you run Puppet. There are several ways to control whether or when an exec
will be applied:
creates
runs theexec
only if a given file doesn't existonlyif
runs theexec
only if a given command succeedsunless
runs theexec
only if a given command fails
To run the command in a specified directory, use the cwd
attribute:
exec { 'Download public key for John': cwd => '/tmp', command => '/usr/bin/wget http://bitfieldconsulting.com/files/john.pub', creates => '/tmp/john.pub', }
To apply the command only when triggered by some other resource, use the refreshonly
attribute:
exec { 'icinga...