Puppet: Conditional file source based on naming convention

thi*_*ice 3 puppet puppetmaster

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
...
Run Code Online (Sandbox Code Playgroud)

因此,我希望该块以伪术语验证模块的资源是否存在,并相应地采取行动:

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'
  }
}
Run Code Online (Sandbox Code Playgroud)

这样一来,人们就不必管理 csv 文件或.pp带有特定于主机的 case 语句的文件 - 这可能吗?

bec*_*est 7

当前资源文件类型文档指定您可以执行file{'/etc/my.cnf': source => [ "puppet:///mysql/etc/my.$hostname.cnf" , "puppet:///mysql/etc/my.cnf" ] }