Easiest way is wrapping it in a defined type.

define my_config() {
  file { $name: ensure => file,
                content => template(...),
  }
}

Inside the template, you can use <%= @name %> or <%= @title %>, because
that is the name of the file being managed in this context.

Use the type like

my_config { [ "foo", "bar" ]: }

It is good practice to pass all non-fact non-hiera variables that are
relevant for the template as parameters to your defined type.

HTH,
Felix

On 12/10/2013 08:44 PM, Mark McWhinney wrote:
> I have a module that needs to create several, similar config files, so I
> am using a template.
> 
> file { "foo" :
>     ensure  => file,
>     content => template("MyTempalte.erb"),
>   }
> file { "bar" :
>     ensure  => file,
>     content => template("MyTempalte.erb"),
>   }
> 
> So far, so good. The issue is that I need to put the name of the file
> into the config file that is created from the template.  I tried <%=
> file %>, but that gives the name of the template file, MyTemplate.erb
>  What I need is the name of the config file e.g. foo or bar.  I poked
> around the documentation but could not the right incantation.  Any ideas?

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/52A84763.5020401%40alumni.tu-berlin.de.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to