Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Im looking for a way to test if a file exist in my client (just test not creation). I've found the way (File.exists) in chef but that wasn't simple with puppet.

Thanks in advance.

share|improve this question

2 Answers 2

up vote 6 down vote accepted

The "native" way to do this without execs if you're on Puppet 2.6.6+:

file { '/path/to/myfile':
  ensure => 'present',
  audit  => 'all',
}

(This functionality exists since Puppet 2.6.0, but there were a number of issues with auditing that only really got hammered out with the 2.6.6 release.)

If you're on an older version, you can also tell the resource to run in noop mode, which will just display a message when Puppet is run and the file doesn't exist:

file { '/path/to/myfile':
  ensure => 'present',
  noop   => 'true',
}
share|improve this answer
    
yeah. this is great with new version ov puppet. ive been working with pre 2.6.0 and have to write my own ruby function for file exist/empty check. –  MealstroM Apr 13 '11 at 6:11

You should create yours own function or use exec with onlyif command. something like :

exec { "mycommand":
  path => "/usr/bin:/usr/sbin:/bin",
  onlyif => "test -f /etc/blalba" //yours command 
}
share|improve this answer
    
ensure => present will create the file if its not existing. bazic only wants to test and not create it. See docs: docs.puppetlabs.com/references/stable/type.html#file –  shakalandy Apr 12 '11 at 10:29
    
Thanks,but nothing interesting in docs. –  bazic Apr 12 '11 at 10:33
    
ive updated my my answer –  MealstroM Apr 12 '11 at 10:36
1  
@MealstroM: Wouldn't "creates => '/etc/blabla'" be better than an "onlyif"? –  freiheit Apr 12 '11 at 15:08
1  
@MealstroM: In this particular case, creates would have the same result and be much simpler (and a bit faster). Yes, in general onlyif does provide more flexibility. –  freiheit Apr 13 '11 at 17:19

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.