Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have several directories and for each I want to set up the same subdirs with puppet.

This obviously doesn't work:

$inst = ['/i1', '/i2', '/i3']
$subdirs = ['subdir1', 'subdir2']

file {"${inst}/${subdirs}":
      ensure=>directory,
      recurse=>true,
      purge=>true,
      force=>true,
      owner=>$username,
      group=>$group,
      source=>"puppet:///modules/mymodule/subdirtemplates/${subdirs}/",
      mode=>'644';
}

There's no way to concatenate each member of the first array with each member of the second array.

In any normal programming language, you'd use two for loops, or some builtin mapping function or something, but in puppet? Do I have to migrate to the new Ruby DSL?

share|improve this question
add comment

1 Answer

hmm. I solved it thus:

$inst = ['/i1', '/i2', '/i3']
#$subdirs = ['subdir1', 'subdir2']

file {$inst:
  ensure=>directory,
  recurse=>true,
  purge=>true,
  force=>true,
  owner=>$username,
  group=>$group,
  source=>"puppet:///modules/mymodule/subdirtemplates/",
  mode=>'644';
}

I made sure that subdirtemplates contained all directories I wanted to be in each instance. It worked for me but maybe someone still has a nicer answer for setting up directory trees in cases where you don't have a template tree.

share|improve this answer
add comment

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.