Issue #11762 has been updated by Daniel Pittman.

Randall Hansen wrote:
> If I understand it:  you'd create a directory of 20 files, and 2 of them 
> would be templates. The first 18 files would be copied verbatim, and the 
> latter 2 parsed with node-specific configuration added.  This would save you 
> having to define 20 file resources individually.  Is that a reasonable 
> summary?

That is about the shape of it, yeah.  At a guess, we would probably want this 
applied to both recursive and non-recursive content, since the disparate 
behaviour of "magic extensions" or whatever we select wouldn't make much sense.
----------------------------------------
Feature #11762: Add File resource option to treat all/some input files as 
templates when recursing subdirectories
https://projects.puppetlabs.com/issues/11762

Author: Daniel Grace
Status: Needs Decision
Priority: Normal
Assignee: Randall Hansen
Category: file
Target version: 
Affected Puppet version: 
Keywords: puppet file resource recursion templates 
Branch: 


While in theory we should be avoiding file resources, it seems like it would be 
handy to be able to recursively copy a directory while treating files within 
that directory as templates -- particularly for quickly adapting an existing 
configuration to Puppet.  Using content => template(...) is fine for individual 
files, but is a headache for a large number of them.

At the simplest level, an additional option to file could be added that says 
"If this is a file, send the generated contents through template() to determine 
the final file contents."

At a more complex level, the following might be added:

* Ability to include/exclude files by suffix, being a binary file, or MIME type 
(presumably harder to implement) 
* Functionality such that if we find a file called bar.erb on the source 
(/etc/puppet/[...]/files/bar.erb) but no file called 'bar', we treat bar.erb as 
a template to generate bar.  If we do have an undecorated 'bar' file, it's 
treated as a regular file (not evaluated as a template).  The template suffix 
(or prefix?) should be customizable in this case.  A few ways this could be 
implemented:
  * templatesuffix/templateprefix parameters.  (e.g. templatesuffix => ".erb")
  * templatepattern paramater: A regexp that -- when it matches a file name -- 
treats that file as an ERB template for an actual file matching the capture 
portion of the expression.  i.e. templatepattern => "^(.*)\.erb$".  The 
question here then is should templatepattern match against just the file name 
or should it match the entire relpath (is .../files/subdir/baz.erb   'baz.erb' 
or 'subdir/baz.erb'?)  The former makes patterns easier to write, the latter 
makes them more powerful.

Scenario: A given user already has a fairly complicated configuration file 
layout for package 'foo' stored in /etc/foo.  Most nodes running 'foo' use 
nearly-identical configuration files with just a handful of machine-specific 
changes.  While it's possible to create a File resource for each individual 
configuration file and template() in the appropriate template, this can be 
cumbersome if there's a large number of files in question.

File resources already have the ability to recurse into directories.  It'd be 
nice to have an option that essentially says "When recursing a directory, if a 
directory entry is a file (rather than a directory/etc), treat the contents of 
it as a template".  The above scenario could then be implemented with the 
following steps:

1. Copy existing contents of /etc/foo to /etc/puppet/module/foo/files
2. Edit files to define machine-specific behavior, treating them as ERB 
templates.
3. Import the entire set of files with something akin to:

<pre>
class Foo {
  file { '/etc/foo':
    ensure => directory,
    recurse => true,
    source => 'foo'
    template => true,  // proposed addition to treat source files as templates.
  }
}
</pre>
   



-- 
You have received this notification because you have either subscribed to it, 
or are involved in it.
To change your notification preferences, please click here: 
http://projects.puppetlabs.com/my/account

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Bugs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/puppet-bugs?hl=en.

Reply via email to