Hi, I''m trying create a custom function that will return an array of file paths for the file type source. Instead of defining the following array for source for each file type: file: { "some_file": source => [ "puppet:///file/$hostname/path", "puppet:///file/$role/ $mode/path", "puppet:///file/$role/path", "puppet:///file/common/ path", ], ... } I''ve created a custom function to return the generated array similar to the following: file: { "some_file": source => find_file(path), ... } I''m getting the following message on the client: err: Could not retrieve catalog from remote server: Error 400 on SERVER: Function ''find_file'' does not return a value at /etc/puppet/ manifests/class/sudo.pp:12 on node tnfs01 The function is located at /var/lib/puppet/lib/puppet/parser/functions/ find_file.rb. Function: module Puppet::Parser::Functions newfunction(:find_file, :type => :rvalue) do |args| filename = args[0] hostname = lookupvar(''hostname'') role = lookupvar(''role'') mode = lookupvar(''mode'') sources = Array.new sources << "puppet:///files/#{hostname}/#{filename}" sources << "puppet:///files/#{role}/#{mode}/#{filename}" sources << "puppet:///files/#{role}/#{filename}" sources << "puppet:///files/common/#{filename}" return sources end end Not sure what I''m doing wrong here. Any help would be greatly appreciated. Also, if there''s already a built-in way to do this in Puppet I''d gladly ditch the custom function, although I''d still like to figure out the problem for future reference. Thanks, Nate -- 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.
Nate
2011-Oct-13 20:44 UTC
[Puppet Users] Re: Problem with custom function returning array
Anybody have any thoughts on this? On Oct 7, 8:50 am, Nate <nathan.schum...@gmail.com> wrote:> Hi, > > I''m trying create acustomfunctionthat willreturnanarrayof file > paths for the file type source. Instead of defining the followingarrayfor source for each file type: > > file: { "some_file": > source => [ "puppet:///file/$hostname/path", "puppet:///file/$role/ > $mode/path", "puppet:///file/$role/path", "puppet:///file/common/ > path", ], > ... > > } > > I''ve created acustomfunctiontoreturnthe generatedarraysimilar > to the following: > > file: { "some_file": > source => find_file(path), > ... > > } > > I''m getting the following message on the client: > > err: Could not retrieve catalog from remote server: Error 400 on > SERVER:Function''find_file'' does notreturna value at /etc/puppet/ > manifests/class/sudo.pp:12 on node tnfs01 > > Thefunctionis located at /var/lib/puppet/lib/puppet/parser/functions/ > find_file.rb. > > Function: > > module Puppet::Parser::Functions > newfunction(:find_file, :type => :rvalue) do |args| > filename = args[0] > hostname = lookupvar(''hostname'') > role = lookupvar(''role'') > mode = lookupvar(''mode'') > sources =Array.new > sources << "puppet:///files/#{hostname}/#{filename}" > sources << "puppet:///files/#{role}/#{mode}/#{filename}" > sources << "puppet:///files/#{role}/#{filename}" > sources << "puppet:///files/common/#{filename}" > returnsources > end > end > > Not sure what I''m doing wrong here. Any help would be greatly > appreciated. Also, if there''s already a built-in way to do this in > Puppet I''d gladly ditch thecustomfunction, although I''d still like > to figure out the problem for future reference. > > Thanks, > > Nate-- 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.
Jacob Helwig
2011-Oct-13 20:50 UTC
Re: [Puppet Users] Re: Problem with custom function returning array
Did you topo part of the function definition, or does it actually have ''returnsources'' at the end of the newfunction block? You should have ''return sources'', ''sources'', or just leave that bit off, since ''sources << "puppet:///files/common/#{filename}"'' will return the value of sources. -- Jacob Helwig On Thu, 13 Oct 2011 13:44:14 -0700, Nate wrote:> > Anybody have any thoughts on this? > > On Oct 7, 8:50 am, Nate <nathan.schum...@gmail.com> wrote: > > Hi, > > > > I''m trying create acustomfunctionthat willreturnanarrayof file > > paths for the file type source. Instead of defining the followingarrayfor source for each file type: > > > > file: { "some_file": > > source => [ "puppet:///file/$hostname/path", "puppet:///file/$role/ > > $mode/path", "puppet:///file/$role/path", "puppet:///file/common/ > > path", ], > > ... > > > > } > > > > I''ve created acustomfunctiontoreturnthe generatedarraysimilar > > to the following: > > > > file: { "some_file": > > source => find_file(path), > > ... > > > > } > > > > I''m getting the following message on the client: > > > > err: Could not retrieve catalog from remote server: Error 400 on > > SERVER:Function''find_file'' does notreturna value at /etc/puppet/ > > manifests/class/sudo.pp:12 on node tnfs01 > > > > Thefunctionis located at /var/lib/puppet/lib/puppet/parser/functions/ > > find_file.rb. > > > > Function: > > > > module Puppet::Parser::Functions > > newfunction(:find_file, :type => :rvalue) do |args| > > filename = args[0] > > hostname = lookupvar(''hostname'') > > role = lookupvar(''role'') > > mode = lookupvar(''mode'') > > sources =Array.new > > sources << "puppet:///files/#{hostname}/#{filename}" > > sources << "puppet:///files/#{role}/#{mode}/#{filename}" > > sources << "puppet:///files/#{role}/#{filename}" > > sources << "puppet:///files/common/#{filename}" > > returnsources > > end > > end > > > > Not sure what I''m doing wrong here. Any help would be greatly > > appreciated. Also, if there''s already a built-in way to do this in > > Puppet I''d gladly ditch thecustomfunction, although I''d still like > > to figure out the problem for future reference. > > > > Thanks, > > > > Nate >
Nan Liu
2011-Oct-13 23:32 UTC
Re: [Puppet Users] Problem with custom function returning array
On Fri, Oct 7, 2011 at 6:50 AM, Nate <nathan.schumann@gmail.com> wrote:> Hi, > > I''m trying create a custom function that will return an array of file > paths for the file type source. Instead of defining the following > array for source for each file type: > > file: { "some_file": > source => [ "puppet:///file/$hostname/path", "puppet:///file/$role/ > $mode/path", "puppet:///file/$role/path", "puppet:///file/common/ > path", ], > ... > }In general more desirable to be explicit about the file you are distributing rather than using this pattern. Moving on to the issue.> I''ve created a custom function to return the generated array similar > to the following: > > file: { "some_file": > source => find_file(path), > ... > }Function seems fine: notice: Scope(Class[main]): puppet:///files/puppet/file.txt puppet:///files/my_role//file.txt puppet:///files/my_role/file.txt puppet:///files/common/file.txt notice: Finished catalog run in 0.02 seconds file: { ... should be file { "some_file": ... Are you using path as a variable instead of the actual file path? file { "some_file": source => find_file("/path/to/file"), ... } HTH, Nan -- 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.
Nate
2011-Oct-14 18:43 UTC
[Puppet Users] Re: Problem with custom function returning array
Thank you all for the responses. For some reason when I was originally testing this function it was giving the error mentioned previously. However, it does seem to be working now. I''m wondering if there wasn''t something cached on the puppet client or a typo somewhere else. Unfortunately I''m relatively new to Puppet and Ruby. The argument to find_file function is actually a relative path like "etc/hosts". We have a production and test environment which would fill in the $mode, and several different system roles for $role. The whole reason I created this function is to have one class defined that would work with all $mode and $role options and to provide the ability to create one-off files if needed used by $host and also a common to all options. This may go against the idea of Puppet, but it will be useful in our environment. Thanks again! Nate On Oct 13, 6:32 pm, Nan Liu <n...@puppetlabs.com> wrote:> On Fri, Oct 7, 2011 at 6:50 AM, Nate <nathan.schum...@gmail.com> wrote: > > Hi, > > > I''m trying create a custom function that will return an array of file > > paths for the file type source. Instead of defining the following > > array for source for each file type: > > > file: { "some_file": > > source => [ "puppet:///file/$hostname/path", "puppet:///file/$role/ > > $mode/path", "puppet:///file/$role/path", "puppet:///file/common/ > > path", ], > > ... > > } > > In general more desirable to be explicit about the file you are > distributing rather than using this pattern. Moving on to the issue. > > > I''ve created a custom function to return the generated array similar > > to the following: > > > file: { "some_file": > > source => find_file(path), > > ... > > } > > Function seems fine: > notice: Scope(Class[main]): puppet:///files/puppet/file.txt > puppet:///files/my_role//file.txt puppet:///files/my_role/file.txt > puppet:///files/common/file.txt > notice: Finished catalog run in 0.02 seconds > > file: { ... should be file { "some_file": ... > > Are you using path as a variable instead of the actual file path? > > file { "some_file": > source => find_file("/path/to/file"), > ... > > } > > HTH, > > Nan-- 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.