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 puppet-users+unsubscribe@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/1689c0a4-9117-46ac-b16b-90b9570464bc%40googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
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 puppet-users+unsubscribe@googlegroups.com. 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.
Cool. That worked. Thank you! On Tuesday, December 10, 2013 11:44:10 AM UTC-8, 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 puppet-users+unsubscribe@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/a3cf365e-6622-40ff-ae98-e4b54739db3a%40googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.