Is it possible to use Puppet to ensure multiple files in a directory are present without defining all of them

puppetscripting

I have a couple hundred one-off servers that have different configuration files that need to be present in a directory. Copies of the files reside on the puppet master.

Within one of my classes I have a default set of configurations that are always pushed to the node, like so:

file { "/etc/someprogram/config/000-default":
  ensure => "present",
  owner => "root",
  group => "root",
  mode =>  0764,
  source => "puppet:///modules/someprogram/000-default",
}

What I would like to have is something like this:

$filearray = directory listing of /etc/puppet/modules/someprogram/files/$fqdn
with each file as an element into array

$filearray.each(
file { "/etc/someprogram/config/$filename":
  ensure => "present",
  owner => "root",
  group => "root",
  mode =>  0764,
  source => "puppet:///modules/someprogram/files/$fqdn/$filename",
}
)

I'm not very familiar with puppet but I'm getting the impression there isn't a way to do this.

Best Answer

You can do what you are trying with this:

file { "/etc/someprogram/config":
    ensure => directory,
    recurse => remote,
    source => "puppet:///modules/someprogram/files/$fqdn"
    #Other options
}

This will copy all of the files in $fqdn to /etc/someprogram/config, overwriting if they already exist.

Related Topic