1

So I have a need to generate a file tree for certain users on Windows.

I need to provide a list of users, preferably from an external fact, and have puppet make sure a set of files is in a directory (but allowing different unmanaged files), and that directory is named as such: C:\VaultWorkspace\username\Vault

So I'll have as many username directories as there are users specified. I want the username directory and files owned by the username user... My best guess is below, but it doesn't work.

I've seen: Is it possible to use Puppet to ensure multiple files in a directory are present without defining all of them? where it looks like "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." is what I want to do, but that post doesn't explain the define...

class inventor {
    case $kernel {
            'linux': {

            }

            'windows': {
  @file {'VaultWorkspace':
  path => "C:/VaultWorkspace/${user}/Vault",
  source => "puppet:///modules/inventor/Vault",
  recurse => true,
  owner => "${user}",
  group => 'Users',
  mode => 0755,
  ensure => present,
  }

  realize File["$inventorusers"]
            }
    }
}

$inventorusers = ['username1','username2','usernamen']
3
  • 1
    What version of puppet on the master/clients? You might be able to take advantage of the new map construct.
    – Zoredache
    Mar 18, 2014 at 15:53
  • If you have un-managed files. You probably want recurse => remote, it is faster.
    – Zoredache
    Mar 18, 2014 at 16:38
  • I am using 3.4.3 of puppet on both.
    – jmp242
    Mar 18, 2014 at 16:46

1 Answer 1

0

A defined type would do the job:

define userworkspace {
  file { "VaultWorkspace-${title}":
    path    => "C:/VaultWorkspace/${title}/Vault",
    source  => "puppet:///modules/inventor/Vault",
    recurse => true,
    owner   => $title,
    group   => 'Users',
    mode    => 0755,
    ensure  => present,
  }
}

$inventorusers = ['username1','username2','usernamen']

userworkspace { $inventorusers: }
2
  • So the only problem I have with this is it seems like I can't use an external fact where I do inventorusers=['username1','username2','usernamen'] because it doesn't turn it into an array? Maybe? How should I format it if I want a list?
    – jmp242
    Mar 18, 2014 at 16:45
  • 1
    Delimit it, and then use the split() function in your manifests.
    – Zoredache
    Mar 18, 2014 at 16:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .