How to call a puppet filetemplate twice with different parameters without using define?
i try to create two different files with one template, because they only diff by one line.
file
{
"/tmp/bootstrap-raid.sh":
content => template("pxe/bootstrap.sh.erb"),
}
file
{
"/tmp/bootstrap-noraid.sh":
content => template("pxe/bootstrap.sh.erb"),
}
bootstrap.sh.erb:
<% if ??? == "???" %>
-r yes \
<% else %>
-r no \
<% end %>
i can't pass a variable by defining it twice like $raid=yes file{} $raid=no file{}
, so i tried to define the variable inside each file{}
with no effort. then i thought about using the targetfilename inside the template like <% if filename == "/tmp/bootstrap-raid.sh" %>
which is also not possible.
how to work call a template twice with different "parameters"
my target is to not defining and calling an extra function in the manifest file, or making two templates. any ideas?
are there any predefined default variables in a template like the filename of the targetfile, the templatename,...?
edit:
another example would be having two php.ini files like in debian, one for the command line and one for the webserver. i want only to exchange the memory limit. but each server needs both php.ini files.
i am looking for a way to pass a hardcoded parameter to the template file or a way that i can if/then/else
based upon the targetfilename.
of course i know that i am able to create a new define, which i can call twice. but i am looking for an easier way.
You can't get the resource name (it seems), but you can get the class. For example:
class bootstrap-raid {
file {
"/tmp/bootstrap-raid.sh":
content => template("/root/bootstrap.sh.erb"),
}
}
class bootstrap-noraid {
file {
"/tmp/bootstrap-noraid.sh":
content => template("/root/bootstrap.sh.erb"),
}
}
And for the template:
<% if name == "bootstrap-raid" %>
-r yes \
<% else %>
-r no \
<% end %>
There's also title
available, which usually means the same thing (at least, I never saw them differ).
Perhaps you should do this with a define?
class bootstrap { define conf ( $israid= undef ) { $loc = $name file { "$loc": content => template(blah.erb); } } }
then call it with
include bootstrap bootstrap::conf { "/loc": israid => '-r yes \'; } bootstrap::conf { "/otherloc": israid => '-r no \'; }
your template will need to handle the israid
variable you can just use an include and keep the logic out of the template (or at least less of the logic in there
<%= israid %>