Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm getting the ball rolling on puppet for my environment - and I'd like to have a conditional file resource based on whether or not the module itself contains a file based on a naming convention.

So visually, assume a module named 'mysql' and it's layout:


So I'd like the block to verify if the resource for the module exists or not, and take action accordingly, in pseudo-terms:

file { '/etc/my.cnf':

  if -f 'puppet:///mysql/etc/my.$hostname.cnf' {
      source => 'puppet:///mysql/etc/my.$hostname.cnf'
  else {
      source => 'puppet:///mysql/etc/my.cnf'

This way one wouldn't have to manage a csv file or the .pp file with a host specific case statement - is this possible?

share|improve this question
up vote 7 down vote accepted specifies you can do file{'/etc/my.cnf': source => [ "puppet:///mysql/etc/my.$hostname.cnf" , "puppet:///mysql/etc/my.cnf" ] }

share|improve this answer
That's a big ol 'DOH, RTFM' for me, shame >.< - thanks! – thinice Jun 1 '12 at 21:41

Your Answer


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.