Get filename for puppet template

puppettemplate

I have a file that I'd like to reuse for a few different purposes. The file is 90% the same across uses, just slight differences. I'd rather not replicate the content across multiple files in puppet, so is there a way to do something like

file { "/tmp/file1" :
  content => template("module/template.erb")
}

file { "/tmp/file2" :
  content => template("module/template.erb")
}

And in the template:

Jack
John
James
<% if file == "/tmp/file2" %>
Jim
<% end %>

Best Answer

You should use a define or a parametrized class, that way you can get name to what you like (IMHO, should be a define):

define filename($template = "mytemplate.erb") {
  file { $name:
    content => template($template)
  }
}

node 'host' {

  filename { "/tmp/file1": }
  filename { "/tmp/file2": }
}

And correct your template to:

Jack
John
James
<% if name == "/tmp/file2" %>
Jim
<% end %>
Related Topic