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 need to create a user account and a lot of files for that user with Puppet.

Works fine with the most straightforward approach, but on every file resource I have to specify owner => 'theuser', which seems horribly redundant (if I don't they end up root-owned).

Is there a way to have a scoped default for the owner? Or something like sudo where puppet runs under that user for a certain set of resources?

share|improve this question
    
are all the files in the same location? –  Mike Mar 7 '13 at 6:18
    
@Mike: a common root folder could be arranged. –  Thilo Mar 7 '13 at 6:19

2 Answers 2

up vote 4 down vote accepted

So if everything is in a single location you can use the recurse option for file

file { "/path/to/files/":
    ensure  => directory,
    recurse => true,
    owner   => "user",
    group   => "group",
    mode    => "700",
    source  => "puppet:///modules/moduleName/path/in/files/",
  }

Then just have all your files in like

modules/ModuleName/path/in/files/

Puppet will put all the files in that module path into /path/to/files on the system owned by that user/group.

share|improve this answer
    
Will it do anything to files that are already in that directory (but not in the module)? –  Thilo Mar 7 '13 at 6:23
1  
if any filename matches it will overwrite them.. you can add a purge => true, to it and it will delete any file on the system that isn't in puppet for that directory –  Mike Mar 7 '13 at 6:24
    
Sweet. That cuts down not just on the owner attribute, but on the multiple file resources altogether. Can this also be made to work with files that are not static, but use content => Template( somehow (some files in that module are templates)? –  Thilo Mar 7 '13 at 6:31
    
if it can work with templates.. i don't know of a way –  Mike Mar 7 '13 at 6:39

To cut down on e.g. the owner attribute you can add some defaults.

File {
  owner => 'user',
  group => 'somegroup',
  mode  => '0444'
}

file {
  '/some/where/file1': source => 'some-source1';
  '/some/where/file2': source => 'some-source2';
  '/some/where/file3': source => 'some-source3';
}

Documentation on resource defaults: http://docs.puppetlabs.com/guides/language_guide.html#resource-defaults

share|improve this answer
    
Do you have a link to the documentation for this default definition feature? –  Thilo Mar 7 '13 at 9:08
1  
@Thilo I added a link to the official documentation about it in the answer. –  pkhamre Mar 7 '13 at 9:57

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.