Hello, folks: I want to include a file into my templates to deduplicate code. However, I''m running into problems with the module path. If I try to include the relative path with code like the following it fails: # Fails require ''foo.rb'' However, a fully qualified path succeeds: # Works as expected require ''/etc/puppet/modules/foobar/templates/foo.rb'' While the latter works it causes problems if I want to move the module. Am I overlooking something here? I''ve grepped through the variables passed into the templates and I don''t see any paths passed in that I could use. Thanks in advance. --Tom Noonan II -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users. For more options, visit https://groups.google.com/groups/opt_out.
Hi, You can use here the concept of partial template. Try including <%= scope.function_template("foo.rb") %> This may help you, please refer http://somethingsinistral.net/blog/partial-templates-with-puppet/ Here is the link, someone has faced the similar issue as including file in template, refer http://stackoverflow.com/questions/16551717/how-to-include-a-subtemplate-in-a-puppet-template. I hope its useful to you. Thanks and Regards, Sneha More, NTT DATA GTS, OSS Center, India On Tuesday, October 1, 2013 8:07:26 AM UTC+5:30, Tom Noonan wrote:> > Hello, folks: > > I want to include a file into my templates to deduplicate code. > However, I''m running into problems with the module path. If I try to > include the relative path with code like the following it fails: > > # Fails > require ''foo.rb'' > > However, a fully qualified path succeeds: > > # Works as expected > require ''/etc/puppet/modules/foobar/templates/foo.rb'' > > While the latter works it causes problems if I want to move the > module. Am I overlooking something here? I''ve grepped through the > variables passed into the templates and I don''t see any paths passed in > that I could use. > > Thanks in advance. > > --Tom Noonan II >-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users. For more options, visit https://groups.google.com/groups/opt_out.
On Tuesday, October 1, 2013 7:02:00 AM UTC-5, Sneha More wrote:> > Hi, > You can use here the concept of partial template. > Try including > > <%= scope.function_template("foo.rb") %> > > This may help you, please refer > http://somethingsinistral.net/blog/partial-templates-with-puppet/ > Here is the link, someone has faced the similar issue as including file in > template, refer > http://stackoverflow.com/questions/16551717/how-to-include-a-subtemplate-in-a-puppet-template > . > >> >>That invokes the Puppet template() function with argument "foo.rb", but from name and usage that appears to be a Ruby source file as opposed to an ERB template. The stackoverflow link looks promising, however, in that the discussion there demonstrates a technique for determining the template file''s location from within the file itself, using the __FILE__ variable. To apply that to ''require''ing a Ruby source file you would probably end up with something like this: <% require File.dirname(__FILE__) + "/foo.rb" %> John -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users. For more options, visit https://groups.google.com/groups/opt_out.
> <% require File.dirname(__FILE__) + "/foo.rb" %>This suits my needs perfectly. Thanks! On Tue, 1 Oct 2013 06:32:15 -0700 (PDT) jcbollinger <John.Bollinger@stJude.org> wrote:> > > On Tuesday, October 1, 2013 7:02:00 AM UTC-5, Sneha More wrote: > > > > Hi, > > You can use here the concept of partial template. > > Try including > > > > <%= scope.function_template("foo.rb") %> > > > > This may help you, please refer > > http://somethingsinistral.net/blog/partial-templates-with-puppet/ > > Here is the link, someone has faced the similar issue as including > > file in template, refer > > http://stackoverflow.com/questions/16551717/how-to-include-a-subtemplate-in-a-puppet-template > > . > > > >> > >> > > That invokes the Puppet template() function with argument "foo.rb", > but from name and usage that appears to be a Ruby source file as > opposed to an ERB template. The stackoverflow link looks promising, > however, in that the discussion there demonstrates a technique for > determining the template file''s location from within the file itself, > using the __FILE__ variable. To apply that to ''require''ing a Ruby > source file you would probably end up with something like this: > > <% require File.dirname(__FILE__) + "/foo.rb" %> > > > John >-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users. For more options, visit https://groups.google.com/groups/opt_out.