The env is Solaris 10, facter 1.5.9, puppet 2.6.8, ruby 1.8.7 p302. I''m trying to call the generate function inside of an erb template and getting an error that the generate function doesn''t exist. The following snippet from http://docs.puppetlabs.com/guides/templating.html leads me to believe what I''m trying is doable and I''m most likely missing something obvious. "Puppet functions can be called by prepending “function_” to the beginning of the function name. For example, including one template inside another:" My testing was in a client server model but I''m able to reproduce it with the following basic example. I''m wondering if anyone sees any problem with how i''m calling the function from inside a template? The manifest,template and generate script gen.pp: file { "/var/tmp/gen-test/genout": content => template("/var/tmp/gen-test/templ.erb"), } templ.erb: genvar=<%= scope.function_generate(["/var/tmp/gen-test/gencom"]) %> gencom: #!/usr/bin/env ruby -w puts "raboof" When the manifest is applied I get this puppet apply gen.pp Failed to parse template /var/tmp/gen-test/templ.erb: undefined method `function_generate'' for #<Puppet::Parser::Scope:0x8e48ac4> at /var/tmp/ gen-test/gen.pp:2 on node lil-derek That error is the same as if I specify a function that obviously doesn''t exist (burrito in this example) which makes me think I''m not calling the generate function correctly. Failed to parse template /var/tmp/gen-test/templ.erb: undefined method `function_burrito'' for #<Puppet::Parser::Scope:0x8e48ac4> at /var/tmp/ gen-test/gen.pp:2 on node lil-derek I''ve been fussing with this for awhile now and would appreciate an input. TIA. -- 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.
Peter Bukowinski
2011-Oct-05 04:53 UTC
Re: [Puppet Users] problem with generate function in template
On Oct 5, 2011, at 12:11 AM, deet wrote:> The env is Solaris 10, facter 1.5.9, puppet 2.6.8, ruby 1.8.7 p302. > > I''m trying to call the generate function inside of an erb template > and getting an error that the generate function doesn''t exist. > The following snippet from http://docs.puppetlabs.com/guides/templating.html > leads me to believe what I''m trying is doable and I''m most likely > missing something obvious. > "Puppet functions can be called by prepending “function_” to the > beginning of the function name. For example, including one template > inside another:" > > My testing was in a client server model but I''m able to reproduce it > with the following basic example. I''m wondering if anyone sees any > problem with how i''m calling the function from inside a template? > > The manifest,template and generate script > gen.pp: > file { "/var/tmp/gen-test/genout": > content => template("/var/tmp/gen-test/templ.erb"), > } > templ.erb: > genvar=<%= scope.function_generate(["/var/tmp/gen-test/gencom"]) %> > gencom: > #!/usr/bin/env ruby -w > > puts "raboof" > > When the manifest is applied I get this > > puppet apply gen.pp > Failed to parse template /var/tmp/gen-test/templ.erb: undefined method > `function_generate'' for #<Puppet::Parser::Scope:0x8e48ac4> at /var/tmp/ > gen-test/gen.pp:2 on node lil-derek > > > That error is the same as if I specify a function that obviously > doesn''t exist (burrito in this example) > which makes me think I''m not calling the generate function correctly. > > Failed to parse template /var/tmp/gen-test/templ.erb: undefined method > `function_burrito'' for #<Puppet::Parser::Scope:0x8e48ac4> at /var/tmp/ > gen-test/gen.pp:2 on node lil-derek > > I''ve been fussing with this for awhile now and would appreciate an > input. > TIA.It sounds like your running into Bug #4549: http://projects.puppetlabs.com/issues/4549 There is a workaround given in the comments. -- Peter M. Bukowinski Sr. Systems Engineer Janelia Farm Research Campus, HHMI -- 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.
> It sounds like your running into Bug #4549:http://projects.puppetlabs.com/issues/4549 >Thanks for the tip. For a work around it looks like I can do the following in the template where generate is called (or any other function) <% Puppet::Parser::Functions.function(''generate'') -%> genvar=<%= scope.function_generate(["/var/tmp/gen-test/gencom"]) %> Or set a variable in the manifest via generate and then just refer to it in the template gen.pp: $var = generate(''/var/tmp/gen-test/gencom'') file { "/var/tmp/gen-test/genout": content => template("/var/tmp/gen-test/templ.erb"), } templ.erb: genvar=<%= var %>> There is a workaround given in the comments. > > -- > Peter M. Bukowinski > Sr. Systems Engineer > Janelia Farm Research Campus, HHMI-- 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.