I have some logic I need in a template, and it needs to use a somewhat long list og hostnames I''d rather keep in a text file, instead of inside the template. Can I open files from a template and if so, what would the path be? would "./list.txt" mean same path as where the template itself is located? Thanks a lot. Mohamed. -- 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''s ruby, you can do whatever ruby allows. A better solution might be to use extlookup, though. On Apr 8, 2011 3:34 PM, "Mohamed Lrhazi" <lrhazi@gmail.com> wrote:> I have some logic I need in a template, and it needs to use a somewhat > long list og hostnames I''d rather keep in a text file, instead of > inside the template. > > Can I open files from a template and if so, what would the path be? > would "./list.txt" mean same path as where the template itself is > located? > > Thanks a lot. > Mohamed. > > -- > 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 topuppet-users+unsubscribe@googlegroups.com.> For more options, visit this group athttp://groups.google.com/group/puppet-users?hl=en.>-- 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.
Mohamed Lrhazi
2011-Apr-08 22:56 UTC
Re: [Puppet Users] Can I read a file from a template?
My File.new(''./legacy.hosts.list'') fails to find the file, which I put in the same place as the template itself. Is extlookup documented in puppetlabs docs? I cant locate it... Thanks a lot. On Fri, Apr 8, 2011 at 6:42 PM, Scott Smith <scott@ohlol.net> wrote:> It''s ruby, you can do whatever ruby allows. > > A better solution might be to use extlookup, though. > > On Apr 8, 2011 3:34 PM, "Mohamed Lrhazi" <lrhazi@gmail.com> wrote: >> I have some logic I need in a template, and it needs to use a somewhat >> long list og hostnames I''d rather keep in a text file, instead of >> inside the template. >> >> Can I open files from a template and if so, what would the path be? >> would "./list.txt" mean same path as where the template itself is >> located? >> >> Thanks a lot. >> Mohamed. >> >> -- >> 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. >> > > -- > 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. >-- 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.
Mohamed Lrhazi
2011-Apr-08 23:11 UTC
Re: [Puppet Users] Can I read a file from a template?
Managed to get te cdw from the template, it is set to: /var/www/puppet/rack I guess it would not be a good idea to store mt data files in such a directory, would it? any pointers to extlookup is documented? or where in the code to look? thanks a lot. On Fri, Apr 8, 2011 at 6:56 PM, Mohamed Lrhazi <lrhazi@gmail.com> wrote:> My File.new(''./legacy.hosts.list'') fails to find the file, which I > put in the same place as the template itself. > > Is extlookup documented in puppetlabs docs? I cant locate it... Thanks a lot. > > > On Fri, Apr 8, 2011 at 6:42 PM, Scott Smith <scott@ohlol.net> wrote: >> It''s ruby, you can do whatever ruby allows. >> >> A better solution might be to use extlookup, though. >> >> On Apr 8, 2011 3:34 PM, "Mohamed Lrhazi" <lrhazi@gmail.com> wrote: >>> I have some logic I need in a template, and it needs to use a somewhat >>> long list og hostnames I''d rather keep in a text file, instead of >>> inside the template. >>> >>> Can I open files from a template and if so, what would the path be? >>> would "./list.txt" mean same path as where the template itself is >>> located? >>> >>> Thanks a lot. >>> Mohamed. >>> >>> -- >>> 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. >>> >> >> -- >> 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. >> >-- 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.
Deliver the file you want to read via puppet (make sure you require the file resource in the one that uses the template). Probably still more optimal to use extlookup tho... I believe its documented on the puppetlabs site but if not google it and I''m sure you''ll find something :) On Apr 8, 2011 4:11 PM, "Mohamed Lrhazi" <lrhazi@gmail.com> wrote:> Managed to get te cdw from the template, it is set to:/var/www/puppet/rack> I guess it would not be a good idea to store mt data files in such a > directory, would it? > > any pointers to extlookup is documented? or where in the code to look? > > thanks a lot. > > > On Fri, Apr 8, 2011 at 6:56 PM, Mohamed Lrhazi <lrhazi@gmail.com> wrote: >> My File.new(''./legacy.hosts.list'') fails to find the file, which I >> put in the same place as the template itself. >> >> Is extlookup documented in puppetlabs docs? I cant locate it... Thanks alot.>> >> >> On Fri, Apr 8, 2011 at 6:42 PM, Scott Smith <scott@ohlol.net> wrote: >>> It''s ruby, you can do whatever ruby allows. >>> >>> A better solution might be to use extlookup, though. >>> >>> On Apr 8, 2011 3:34 PM, "Mohamed Lrhazi" <lrhazi@gmail.com> wrote: >>>> I have some logic I need in a template, and it needs to use a somewhat >>>> long list og hostnames I''d rather keep in a text file, instead of >>>> inside the template. >>>> >>>> Can I open files from a template and if so, what would the path be? >>>> would "./list.txt" mean same path as where the template itself is >>>> located? >>>> >>>> Thanks a lot. >>>> Mohamed. >>>> >>>> -- >>>> You received this message because you are subscribed to the GoogleGroups>>>> "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. >>>> >>> >>> -- >>> You received this message because you are subscribed to the GoogleGroups>>> "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. >>> >> > > -- > 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 topuppet-users+unsubscribe@googlegroups.com.> For more options, visit this group athttp://groups.google.com/group/puppet-users?hl=en.>-- 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.
This works for me inside of a template: Puppet::Parser::Files.find_template("mymodule/myfile") Allan. -- 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.
Mohamed Lrhazi
2011-Apr-09 18:50 UTC
Re: [Puppet Users] Re: Can I read a file from a template?
Hi Allan, would mind sharing a piece of manifest/template showing how I can use that statement? Thanks a lot. Mohamed. On Sat, Apr 9, 2011 at 9:59 AM, Allan Clark <napta2k@gmail.com> wrote:> This works for me inside of a template: > Puppet::Parser::Files.find_template("mymodule/myfile") > > Allan. > > -- > 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. > >-- 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 Allan, would mind sharing a piece of manifest/template showing how > I can use that statement? >The below code will look for the files mentioned in $filelist inside the files directory of the module "some_module" and import the contents of the file in to the template. In my case each file contains a single line so it works out rather well. Hope this helps. Allan $filelist = [ ''file1.txt'', ''file2.txt''] <% filelist.sort.each do |my_file| -%> <% File.open(Puppet::Module::find_template("some_module/"+my_file)).each { |line| _erbout << line } -%> <% end -%> -- 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.
Mohamed Lrhazi
2011-Apr-11 13:00 UTC
Re: [Puppet Users] Re: Can I read a file from a template?
Great thanks a lot. On Mon, Apr 11, 2011 at 4:54 AM, Allan Clark <napta2k@gmail.com> wrote:>> Hi Allan, would mind sharing a piece of manifest/template showing how >> I can use that statement? >> > > The below code will look for the files mentioned in $filelist inside > the files directory of the module "some_module" > and import the contents of the file in to the template. In my case > each file contains a single line so it works out > rather well. > > Hope this helps. > > Allan > > $filelist = [ ''file1.txt'', ''file2.txt''] > > <% filelist.sort.each do |my_file| -%> > <% > File.open(Puppet::Module::find_template("some_module/"+my_file)).each > { |line| _erbout << line } -%> > <% end -%> > > -- > 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. > >-- 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.