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.

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.

share|improve this question
1  
Would you be alright with recursively managing the directory these reside in (recurse => true on the file type), instead of declaring each file as a separate resource? –  Shane Madden Feb 10 '14 at 22:41

3 Answers 3

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.

share|improve this answer
1  
Also take a look at recurse => remote if the directory in question will have local files that are not pushed by the puppet server. –  Zoredache Feb 10 '14 at 23:18
    
That is a good tip, I didn't know this had been added to the spec, edited original to reflect this. –  meatflag Feb 11 '14 at 0:00

If you want to define multiple files in a directory without recursing the whole directory, you can use an array - like this:

$myfiles = [ "/my/dir/file1", "/my/dir/file2", ]
file { $myfiles:
    ensure => "present",
    owner  => "root",
    group  => "root",
    mode   =>  0644,
    source => "puppet:///modules/someprogram/$fqdn/$name",
}

Of course, with long paths to "/my/dir" or lots of files, it would get a little unwieldy, so in that case you'd be better off creating a define which included the directory path, and just pass the array of filenames to it.

share|improve this answer
    
this unfortunately does not work when you have an alias set on the file :/ –  cweiske Apr 29 '14 at 15:05
1  
Looks like you have a typo $myfiles -> $files –  Fabrizio Regini Oct 14 '14 at 13:18
    
Thanks @FabrizioRegini - fixed –  Paul Gear Oct 24 '14 at 22:57
    
This will not work. You cannot reference $name here. That only works if it's a defined type. –  faker Jan 2 at 13:19

Here is an example of how I do this:

file {
        [
        '/sys/block/sda/queue/scheduler',
        '/sys/block/sdb/queue/scheduler',
        '/sys/block/sdc/queue/scheduler',
        '/sys/block/sdd/queue/scheduler',
        '/sys/block/sde/queue/scheduler',
        '/sys/block/sdf/queue/scheduler'
        ]:
  ensure  => 'file',
  content => 'deadline',
  group   => '0',
  mode    => '644',
  owner   => '0',
  type    => 'file',
}

In the above example, I am assigning the deadline I/O scheduler to each of the disks on a given server through Puppet.

share|improve this answer

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.