Hi all, I have a situation where I want to use the same template to create two different files in two different classes. I''ve tried to lookup some information on what is possible with templates, how advanced you can get, but haven''t found much. I guess it''s one of the areas where I should contribute to the docs - once I figured out what I can do, that is... ;-) Ex: foobar.pp: ---------- class foo { file { "/etc/foofile": content => template("template.erb"), } } class bar { file { "/etc/barfile": content => template("template.erb"), } } template.erb: ------------- <% if name.include? "foofile" -%> This is foofile <% else -%> This is barfile <% end -%> I''m not a big ruby hacker - yet ;-) I know that I can test the contents of a variable with "variablename.include?". But can I access the "name" of the calling file...? -- Med venlig hilsen Juri Rischel Jensen Fab:IT ApS Vesterbrogade 50 DK-1620 København Tlf: 70 202 407 / Fax: 33 313 640 www.fab-it.dk / juri@fab-it.dk
On Aug 24, 2007, at 6:57 AM, Juri Rischel Jensen wrote:> <% if name.include? "foofile" -%> > This is foofile > <% else -%> > This is barfile > <% end -%> > > I''m not a big ruby hacker - yet ;-) I know that I can test the > contents of a variable with "variablename.include?". But can I access > the "name" of the calling file...?That won''t work, because I don''t currently set the file name in a variable available in the template. Just set a variable specially in each class before you call the template. -- Yesterday upon the stair I met a man who wasn''t there. He wasn''t there again today -- I think he''s from the CIA. --------------------------------------------------------------------- Luke Kanies | http://reductivelabs.com | http://madstop.com
Luke Kanies schrieb:> On Aug 24, 2007, at 6:57 AM, Juri Rischel Jensen wrote: > > >> <% if name.include? "foofile" -%> >> This is foofile >> <% else -%> >> This is barfile >> <% end -%> >> >> I''m not a big ruby hacker - yet ;-) I know that I can test the >> contents of a variable with "variablename.include?". But can I access >> the "name" of the calling file...? >> > > That won''t work, because I don''t currently set the file name in a > variable available in the template. >Are type-parameters and their values at all accessible as a variable at this moment?> Just set a variable specially in each class before you call the > template. > > -- > Yesterday upon the stair > I met a man who wasn''t there. > He wasn''t there again today -- > I think he''s from the CIA. > --------------------------------------------------------------------- > Luke Kanies | http://reductivelabs.com | http://madstop.com > > > _______________________________________________ > Puppet-users mailing list > Puppet-users@madstop.com > https://mail.madstop.com/mailman/listinfo/puppet-users >
On Aug 24, 2007, at 10:20 AM, Simon Mügge wrote:> Are type-parameters and their values at all accessible as a > variable at > this moment?Yes. -- Life is like playing a violin in public and learning the instrument as one goes on. -- Samuel Butler --------------------------------------------------------------------- Luke Kanies | http://reductivelabs.com | http://madstop.com
Luke Kanies schrieb:> On Aug 24, 2007, at 10:20 AM, Simon Mügge wrote: > > >> Are type-parameters and their values at all accessible as a >> variable at >> this moment? >> > > Yes. >Fair enough. After loking through all 37 Pages that where returned when I searched for "variable" in "Wiki" I seem to have to alter the question somewhat: How (as in "by what syntax") are type-parameters and their values accessible as variables in templates and classes?> -- > Life is like playing a violin in public and learning the instrument as > one goes on. -- Samuel Butler > --------------------------------------------------------------------- > Luke Kanies | http://reductivelabs.com | http://madstop.com > > > _______________________________________________ > Puppet-users mailing list > Puppet-users@madstop.com > https://mail.madstop.com/mailman/listinfo/puppet-users >
On Aug 24, 2007, at 11:30 AM, Simon Mügge wrote:> How (as in "by what syntax") are type-parameters and their values > accessible as variables in templates and classes?Maybe I misunderstood at first -- do you mean the attributes of a native type, or do you mean the attributes passed in to a defined type? The former are essentially inaccessible, but the latter behave like any other variable and thus are accessed like any other. -- Risk! Risk anything! Care no more for the opinions of others, for those voices. Do the hardest thing on earth for you. Act for yourself. Face the truth. -- Katherine Mansfield --------------------------------------------------------------------- Luke Kanies | http://reductivelabs.com | http://madstop.com
Luke Kanies schrieb:> On Aug 24, 2007, at 11:30 AM, Simon Mügge wrote: > > >> How (as in "by what syntax") are type-parameters and their values >> accessible as variables in templates and classes? >> > > Maybe I misunderstood at first -- do you mean the attributes of a > native type, or do you mean the attributes passed in to a defined type? > > The former are essentially inaccessible, but the latter behave like > any other variable and thus are accessed like any other. >Sadly I was talking about the native ones ;) Because of our setup I can hardly use anything but defined types so I really got used to being able to access theses variables and was getting exited about having access to the parameters of native ones as well. (Not that I have an actual need for that right now, but with puppet you never know what else fun stuff you could do once you know what is possible.. ;) )> -- > Risk! Risk anything! Care no more for the opinions of others, for > those > voices. Do the hardest thing on earth for you. Act for yourself. Face > the truth. -- Katherine Mansfield > --------------------------------------------------------------------- > Luke Kanies | http://reductivelabs.com | http://madstop.com > > > _______________________________________________ > Puppet-users mailing list > Puppet-users@madstop.com > https://mail.madstop.com/mailman/listinfo/puppet-users >
On Aug 24, 2007, at 2:07 PM, Simon Mügge wrote:> Sadly I was talking about the native ones ;) > Because of our setup I can hardly use anything but defined types so I > really got used to being able to access theses variables and was > getting > exited about having access to the parameters of native ones as well. > (Not that I have an actual need for that right now, but with puppet > you > never know what else fun stuff you could do once you know what is > possible.. ;) )There''s no specific facility for this right now. It could be added if there were sufficient demand, but it would never be as straightforward as it is in the language. -- A government that robs Peter to pay Paul can always depend on the support of Paul. -- George Bernard Shaw --------------------------------------------------------------------- Luke Kanies | http://reductivelabs.com | http://madstop.com