4

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 %>
Noodles
  • 1,416

2 Answers2

5

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 %>
Torian
  • 2,444
0

It sounds like you want to build a config file from fragments ?

http://projects.puppetlabs.com/projects/puppet/wiki/Generating_a_config_file_from_fragments

I've not tried this yet, but I want to. Let me know how it goes if you try this.

Sirex
  • 5,585