A collection of task oriented solutions in Puppet


Don't run exec if $file exists


You have an exec that creates a file or directory that should only run if it doesn't already exist.


class absent_file_exec {

  exec { 'create_needed_directory':
    command => '/bin/mkdir -p /tmp/needed/directory',
    creates => '/tmp/needed/directory'



This is such a common requirement that puppet has a single property that "does the right thing". As long as the file / directory specified in creates exists puppet won't run the exec. It doesn't even cause clutter in the logs!

See also