A collection of task oriented solutions in Puppet

 

Set a default $PATH for all execs

Challenge

You've had enough of specifying a complete 'path =>' on each exec and you want a more global solution

Solution

class global_exec_path {

  # put this somewhere global, like site.pp
  Exec { path => [ '/bin/', '/sbin/' , '/usr/bin/', '/usr/sbin/' ] }

  # alternative, compact, format
  Exec { path => '/bin/:/sbin/:/usr/bin/:/usr/sbin/' }

  # uses the globally specified path
  exec { 'make_foo_state':
    command => 'mkdir -p /tmp/foo/state',
  }

  # overrides the global path for this command
  exec { 'my_local_command':
    command => 'my_special_local_command',
    path    => '/usr/local/sbin/',
  }

}

Explanation

Adding a path to each and every exec is annoying, easy to forget and leads to unneeded duplication. By placing the Exec shown above in a global location (like your site.pp file) all execs will use that path by default, while still allowing you to add extra directories to the path where needed.