On Friday, November 22, 2013 6:50:27 PM UTC-6, erkules wrote:
>
> Ahoi, 
>
> On Thu, Nov 21, 2013 at 12:01:14PM +0100, Felix Frank wrote: 
> > Hi, 
> > 
> > tough call. You may have to replicate the file type in a defined type 
> > like so: 
> > 
> > define my_file($owner="root",$mode="644",...,$template="") { 
> > 
> >   if $template { File[$name] { content => template($template) } } 
> > 
> >   file { $name: owner => $owner, ... } 
> > } 
> > 
> > Then you can create_resource('my_file',hiera('input')) and pass an 
> > actual "template" parameter to your define. 
> > 
>
> Damn thats look quite a *little* bit more complicated. 
> It evens look some kind of hack. Thats ok with me :) 
> Is there a place to do RTFM about when things are evaluated? 
> At least so I can understand why I need File[$name]? 
>
>

The manual is here: http://docs.puppetlabs.com/puppet/3/reference/.  I 
recommend you at least read the entire "The Puppet Language" section, and 
that you at least skim the "Resource Types" and "Functions" subsections of 
the "Generated References" section.  As far as the code Felix proposed, it 
uses a resource parameter override.  You can read about that, specifically, 
here: 
http://docs.puppetlabs.com/puppet/3/reference/lang_resources.html#amending-attributes-with-a-collector.

And yes, resource parameter overrides are somewhat of a hack, though useful 
at times.  In this case, however, I think they are unnecessary.  If you are 
going to add a defined type to hang the behavior on anyway, then why not 
just make it unconditionally define the content via a template?  Then you 
can achieve the same thing a bit more naturally via a definition such as 
this one:

define mymodule::templated_file(
    $owner = 'root',
    $mode='0644',
    ... <no $content parameter> ...
    $template) {
  file { $title:
    owner => $owner,
    mode => $mode,
    # ...
    content => template($template)
  }
}


John

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to puppet-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/95eeebb1-38d7-4f4e-a84f-e91287298c17%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to