So, I''m into templating. I *like* templating. What I *don''t*
like, of
course, is to have to use multiple, similar templates for different output
files. So, let''s work a concrete example. Suppose I have a template
"standard_profile.erb" which looks like this:
install_type initial_install>
> system_type standalone
>
> partitioning explicit
>
> <% if zfs_root == "undef" -%>
>
> fdisk all solaris all
>
> boot_device any preserve
>
> filesys rootdisk.s1 16384 swap
>
> filesys rootdisk.s0 40960 /
>
> filesys rootdisk.s7 free /export
>
> <% elsif zfs_root == "c3s" %>
>
> pool rootpool auto 16g 16g mirror c3t0d0s0 c3t4d0s0
>
> fdisk c3t0d0 solaris all
>
> fdisk c3t4d0 solaris all
>
> <% else %>
>
> pool rootpool auto 16g 16g mirror <%= zfs_root %>t0d0s0 <%=
zfs_root
>> %>t1d0s0
>
> fdisk <%= zfs_root %>t0d0 solaris all
>
> fdisk <%= zfs_root %>t1d0 solaris all
>
> <% end -%>
>
> cluster SUNWCprog
>
> cluster SUNWCgna11y delete
>
> cluster SUNWCgna11ydev delete
>
>
From this I generate 2 different files, one which does ZFS root, and one
which doesn''t (actually, it generates more than that, as I pass in
zfs_root=>"c1" or whatever is necessary. However, while this is
very
flexible, it''s also very ... specific. As in, the define that
I''ve created
to use this file isn''t really re-usable elsewhere:
define profile_file($zfs_root = "undef") {>
> file{"/jumpstart/Profiles/$name":
>
> require => File["/jumpstart/Profiles"],
>
> content => template("jumpstart/solaris_profile.erb"),
>
> mode => 0644
>
> }
>
> }
>
>
>
What I would much rather be able to do is introspection. This ERB is being
evaluated in the context of a source file (.pp), modules, class, and file
resource. If I could even look at the file resource, I''d be able to
make
decisions in the more general case. Otherwise, I end up with a bunch of
defines sprinkled all over my manifests, all of which do the same thing:
bring a value into the ERB scope as a named variable.
Of course, it just now occurred to me that I can create a define like this:
> define smart_template($module, $mode = 0644, $args = undef) {
>>
>> $this_filename = $name
>>
>> $this_short_filename = inline_template("<%>>>
this_filename.split(/\//)[-1] %>")
>>
>> $template_file = "${module}/${this_short_filename}.erb"
>>
>> file{$name:
>>
>> content => template($template_file),
>>
>> mode => $mode
>>
>> }
>>
>> }
>>
>>
>>
I guess this will give me the flexibility I want, because now I have not
just the filename in scope, but the module name and whatever random args I
define, but it still feels somewhat ... unclean. Does someone have a better
idea?
--
You received this message because you are subscribed to the Google Groups
"Puppet Users" group.
To post to this group, send email to puppet-users@googlegroups.com.
To unsubscribe from this group, send email to
puppet-users+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/puppet-users?hl=en.