Puppet – How to Do a File/Dir Exists Conditional in Puppet

puppet

I'm trying to write a function in puppet that will do a fail if the passed directory path does not exist.

if File["/some/path"] always returns true, and if defined(File["/some/path"]) only returns true if the resource is defined in puppet, regardless of whether it actually exists.

Is there a way to do this with a simple if statement?

Thanks

Best Answer

Workaround for this: use onlyif on an exec "test" and require it in your action you want to execute:

exec {"check_presence":
  command => '/bin/true',
  onlyif => '/usr/bin/test -e /path/must/be/available',
}

whatever {"foo...":
  .....
  require => Exec["check_presence"],
}
Related Topic