I need to be able to include a line in a template, based on presence and value of a variable, something like this: # file.erb blah blah blah <% if role == "fast" -%> this line is here now <% end -%> I only want the line to be included if $role exists and is equal to fast. If $role doesn''t exist, or doesn''t equal "fast", it shouldn''t include the line: Jul 24 19:59:40 lonengbld01 puppetmasterd[3095]: Failed to parse template repo/R edHat-4/extras.repo: Could not find value for ''role'' at /etc/puppet/modules/repo /manifests/init.pp:121 on node blah What would be the correct syntax? Thanks --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Jul 24, 2009, at 10:17 PM, lance dillon wrote:> I need to be able to include a line in a template, based on presence > and value of a variable, something like this: > > # file.erb > blah > blah blah > <% if role == "fast" -%> > this line is here now > <% end -%> > > > > I only want the line to be included if $role exists and is equal to > fast. If $role doesn''t exist, or doesn''t equal "fast", it shouldn''t > include the line: > > Jul 24 19:59:40 lonengbld01 puppetmasterd[3095]: Failed to parse > template repo/R > edHat-4/extras.repo: Could not find value for ''role'' at /etc/puppet/ > modules/repo > /manifests/init.pp:121 on node blah > > What would be the correct syntax? > > Thanks > >Try with something like: <%- if role == "fast" -%> <%- line = "The line you want to print" -%> <%- end -%> <%= line -%> Regards --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Jul 24, 2009, at 11:27 PM, Bjørn Dyresen wrote:> > On Jul 24, 2009, at 10:17 PM, lance dillon wrote: > >> I need to be able to include a line in a template, based on >> presence and value of a variable, something like this: >> >> # file.erb >> blah >> blah blah >> <% if role == "fast" -%> >> this line is here now >> <% end -%> >> >> >> >> I only want the line to be included if $role exists and is equal to >> fast. If $role doesn''t exist, or doesn''t equal "fast", it >> shouldn''t include the line: >> >> Jul 24 19:59:40 lonengbld01 puppetmasterd[3095]: Failed to parse >> template repo/R >> edHat-4/extras.repo: Could not find value for ''role'' at /etc/puppet/ >> modules/repo >> /manifests/init.pp:121 on node blah >> >> What would be the correct syntax? >> >> Thanks >> >> > > Try with something like: > > <%- if role == "fast" -%> > <%- line = "The line you want to print" -%> > <%- end -%> > <%= line -%> > >A bit to quick there. For this to work you have to feed the template with the variable. You can just feed $role with a default value. eg default.. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Try with something like:> > <%- if role == "fast" -%> > <%- line = "The line you want to print" -%> > <%- end -%> > <%= line -%> > > > > A bit to quick there. For this to work you have to feed the template with > the variable. You can just feed $role with a default value. eg default.. > >The thing is I have a lot of node definitions, and every node includes this class. I don''t want to have to edit every node definition in order to get that line in just a couple of nodes. Maybe change the class so it concats another template/file onto the end of it if $role is set, although I''m not quite sure how to do that yet without experimentation. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Jul 25, 2009, at 2:09 AM, lance dillon wrote:> > >> Try with something like: >> >> <%- if role == "fast" -%> >> <%- line = "The line you want to print" -%> >> <%- end -%> >> <%= line -%> >> >> > > A bit to quick there. For this to work you have to feed the template > with the variable. You can just feed $role with a default value. eg > default.. > > > The thing is I have a lot of node definitions, and every node > includes this class. I don''t want to have to edit every node > definition in order to get that line in just a couple of nodes. > > Maybe change the class so it concats another template/file onto the > end of it if $role is set, although I''m not quite sure how to do > that yet without experimentation. > >You dont have to specify it on every node. Thats what a default value is for. Take this as an example: define your_definition($role=default) { file { "/path/to/your/file": ensure => present, content => template("your_template") } } Now, if you call it with your_definition { "resource_name": } $role will have the value "default" in your template if you call it with your_definition { "resource_name": role => "fast", } your $role will have the value fast Not what you want, since you would have to flick a switch on your node definition, but I tend to deal these issues like this: class yourmodulename { $role = "default" your_definition { "resource_name": role => "$role", } } define yourmodulename::your_definition($role=default) { file { "/path/to/file/to/controll": ensure => present, content => template("yourmodulename/templatename") } } Then you can subclass this and override the $role=default So the subclass in the module would look like: class yourmodulename::yoursubclass inherits yourmodulename { $role = "fast" Your_definition[''resource_name''] { role => "$role" } } In that case every place you include the subclass the template is fed with "fast" as the value for $role. Im sure you can find other ways to deal with it all well. Regards --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hi, On 24.07.2009, at 22:17, lance dillon wrote:> > I only want the line to be included if $role exists and is equal to > fast. If $role doesn''t exist, or doesn''t equal "fast", it shouldn''t > include the line: > > Jul 24 19:59:40 lonengbld01 puppetmasterd[3095]: Failed to parse > template repo/R > edHat-4/extras.repo: Could not find value for ''role'' at /etc/puppet/ > modules/repo > /manifests/init.pp:121 on node blahWe use: <% if defined?(role) and role == "fast" -%> this line is here now <% end -%> Bye. udo. -- ---[ Institute of Cognitive Science @ University of Osnabrueck ---[ Albrechtstrasse 28, D-49076 Osnabrueck, 969-3362 ---[ Documentation: https://doc.ikw.uni-osnabrueck.de
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Just a note... defined?(foo) doesn''t work. You have to use: has_variable?("foo") Found that out the hard way :-/. Trevor On 07/25/2009 01:21 PM, Udo Waechter wrote:> Hi, > > On 24.07.2009, at 22:17, lance dillon wrote: >> >> I only want the line to be included if $role exists and is equal to >> fast. If $role doesn''t exist, or doesn''t equal "fast", it shouldn''t >> include the line: >> >> Jul 24 19:59:40 lonengbld01 puppetmasterd[3095]: Failed to parse >> template repo/R >> edHat-4/extras.repo: Could not find value for ''role'' at >> /etc/puppet/modules/repo >> /manifests/init.pp:121 on node blah > > > > We use: > > <% if defined?(role) and role == "fast" -%> > this line is here now > <% end -%> > > Bye. > udo.-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) iEYEARECAAYFAkprp0MACgkQyjMdFR1108CEZACglGer6GJxiCp0DVn+kDLze8Ys eK8An0kWfS0MxfJvbEL87Xwpx22WzFTQ =FqCu -----END PGP SIGNATURE----- --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---