Bill Anderson
2011-May-19 22:10 UTC
[Puppet Users] custom function from .24.6 not working in 2.6 (from squeeze)
I''m in the process of upgrading an existing installation from .24.x to 2.6. We seem to have a custom function that is throwing the error: "err: Could not retrieve catalog from remote server: Error 400 on SERVER: private method `gsub'' called for #<Array:0x7fdcebf3bbf8> at /etc/puppet/manifests/classes/apache-php.pp:72" Here is the function: """ # Checks if a file exists on the puppet maser Puppet::Parser::Functions::newfunction(:bbcom_file_exists, :type => :rvalue, :doc => "Checks if the given file exists on the puppet master.") do |vals| ret = false vals.each do |file| # First convert our $puppet.... urls to local filesystems urls # We do this to allow the caller to use the same urls array # in other parts of the recipe. file = file.gsub("puppet:///appconf/", "/etc/cdir/config/") # Now do the same for internal server files file = file.gsub("puppet:///files/", "/etc/puppet/files/") unless file =~ /^#{File::SEPARATOR}/ raise Puppet::ParseError, "Files must be fully qualified" end if File.exists?(file) ret = true break end end ret end """ The function is used as a conditional: given a list of files puppet may be managing, if any of them exist on the server, then do this other thing (so far it usually means "manage this other file too"). Personally I''d love to be able to remove it as it seems clunky to me; but failing that if someone can point out why it is failing in 2.6 and how to fix it I would greatly appreciate it. I''m not much of a Ruby guy so while I understand _what_ the error is telling me, fixing it is a different story. Cheers, Bill -- 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.
jcbollinger
2011-May-20 13:47 UTC
[Puppet Users] Re: custom function from .24.6 not working in 2.6 (from squeeze)
On May 19, 5:10 pm, Bill Anderson <ucnt...@gmail.com> wrote:> I''m in the process of upgrading an existing installation from .24.x to 2.6. > > We seem to have a custom function that is throwing the error: > "err: Could not retrieve catalog from remote server: Error 400 on SERVER: > private method `gsub'' called for #<Array:0x7fdcebf3bbf8> at > /etc/puppet/manifests/classes/apache-php.pp:72" > > Here is the function: > """ > # Checks if a file exists on the puppet maser > Puppet::Parser::Functions::newfunction(:bbcom_file_exists, :type => :rvalue, > :doc => "Checks if the given file exists on the puppet master.") do > |vals| > ret = false > > vals.each do |file| > # First convert our $puppet.... urls to local filesystems urls > # We do this to allow the caller to use the same urls array > # in other parts of the recipe. > file = file.gsub("puppet:///appconf/", "/etc/cdir/config/") > > # Now do the same for internal server files > file = file.gsub("puppet:///files/", "/etc/puppet/files/") > > unless file =~ /^#{File::SEPARATOR}/ > raise Puppet::ParseError, "Files must be fully qualified" > end > if File.exists?(file) > ret = true > break > end > end > ret > end > """ > The function is used as a conditional: given a list of files puppet may be > managing, if any of them exist on the server, then do this other thing (so > far it usually means "manage this other file too"). > > Personally I''d love to be able to remove it as it seems clunky to me; but > failing that if someone can point out why it is failing in 2.6 and how to > fix it I would greatly appreciate it. I''m not much of a Ruby guy so while I > understand _what_ the error is telling me, fixing it is a different story.It looks like at least one function argument is being received as an array instead of as a string. It may be that 0.24.x was flattening that array into a series of individual arguments, whereas 2.6.x does not. If that''s the case, then you may be able to fix the problem by changing vals.each do |file| to vals.flatten.each do |file| Alternatively, you may be able to approach the problem on the manifest side by passing multiple arguments instead of an array. I agree that the function and the usage you describe is suspect. It is dicey whenever a manifest is conditional on anything other than (ultimately) nodes'' facts. I don''t see a good reason why the manifest should not *know* whether any particular file is (supposed to be) managed for a particular node. Moreover, it''s not safe to assume that the presence of a file on the master implies that a corresponding file is being / supposed to be managed for any particular node. John -- 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.
Bill Anderson
2011-May-20 16:55 UTC
[Puppet Users] Re: custom function from .24.6 not working in 2.6 (from squeeze)
On Friday, May 20, 2011 7:47:54 AM UTC-6, jcbollinger wrote:> > > > > It looks like at least one function argument is being received as an > array instead of as a string. It may be that 0.24.x was flattening > that array into a series of individual arguments, whereas 2.6.x does > not. If that''s the case, then you may be able to fix the problem by > changing > > vals.each do |file| > > to > > vals.flatten.each do |file| > > Alternatively, you may be able to approach the problem on the manifest > side by passing multiple arguments instead of an array. >Thanks, that works. I''m still going to look for finding a better solution. I *quite* want to get upgraded. I suspect some of the "new to us" features will make this easier. If nothing else I''d rather see a boolean variable handle it. At least that is easily readable and discoverable. Cheers, Bill -- 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.