3

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:

mysql/
    /files
        /etc/
            my.cnf
            my.hostname1.cnf
            my.hostname2.cnf
     /manifests
            init.pp
...

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?

thinice
  • 4,716
  • 21
  • 38

1 Answers1

7

The current resource file type documentation specifies you can do file{'/etc/my.cnf': source => [ "puppet:///mysql/etc/my.$hostname.cnf" , "puppet:///mysql/etc/my.cnf" ] }

рüффп
  • 620
  • 1
  • 11
  • 25
becomingwisest
  • 3,328
  • 20
  • 18