running 0.24.7
According to the language tutorial I should be able to do:
$ssh_users = [ ''myself'', ''someone'' ]
class test {
$ssh_users += [''someone_else'']
}
I''m trying to append to an array within a class, so i''m doing:
class test {
$metrics = [''a'',''b'']
$metrics += [''''c]
}
With the above I get the following:
err: Could not retrieve catalog: Cannot append, variable metrics is
defined in this scope at
/etc/puppet/production/modules/mymodule/manifests/metrics.pp:132 on
node host.internal
Can I only append to the variable once inside a class? I''m not
worried about the order they get appended.
I''m doing this so I can wrap some logic around appending variables to
the array.
Thanks,
Matt
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
Matt wrote:> According to the language tutorial I should be able to do: > > $ssh_users = [ ''myself'', ''someone'' ] > > class test { > $ssh_users += [''someone_else''] > } > > I''m trying to append to an array within a class, so i''m doing: > > class test { > $metrics = [''a'',''b''] > $metrics += [''''c] > } > > With the above I get the following: > > err: Could not retrieve catalog: Cannot append, variable metrics is > defined in this scope at > /etc/puppet/production/modules/mymodule/manifests/metrics.pp:132 on > node host.internal > > Can I only append to the variable once inside a class? I''m not > worried about the order they get appended.Hi Matt, sorry for the late answer. Yes, you cann assign/alter a variable only once within a scope. A possible workaround would be a puppet function which takes any number of arrays and returns their concatenation (or (distinct) union). Regards, DavidS --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
David Schmitt wrote:> Matt wrote: >> According to the language tutorial I should be able to do: >> >> $ssh_users = [ ''myself'', ''someone'' ] >> >> class test { >> $ssh_users += [''someone_else''] >> } >> >> I''m trying to append to an array within a class, so i''m doing: >> >> class test { >> $metrics = [''a'',''b''] >> $metrics += [''''c] >> } >> >> With the above I get the following: >> >> err: Could not retrieve catalog: Cannot append, variable metrics is >> defined in this scope at >> /etc/puppet/production/modules/mymodule/manifests/metrics.pp:132 on >> node host.internal >> >> Can I only append to the variable once inside a class? I''m not >> worried about the order they get appended. > > Hi Matt, > > sorry for the late answer. > > Yes, you cann assign/alter a variable only once within a scope. > > A possible workaround would be a puppet function which takes any number > of arrays and returns their concatenation (or (distinct) union).That''d look like this: -- 8< ------------ # concat.rb # concatenate the contents of arrays module Puppet::Parser::Functions newfunction(:concat, :type => :rvalue) do |args| result = [] args.each do |arg| result = result.concat(arg) end result end end -- 8< ------------ Put this into a module at plugins/puppet/parser/functions/ und use it like this: | $base_metrics = [''a'', ''b''] | $extended_metrics = [''c''] | $metrics = concat($base_metrics, $extended_metrics) I''ll add the function to the common module, since I just needed similar functionality for a client of mine. Regards, DavidS --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
David Schmitt wrote:> A possible workaround would be a puppet function which takes any number > of arrays and returns their concatenation (or (distinct) union).Shameless plug: I have such a function in my ''nsc-puppet-utils'' module at http://www.nsc.liu.se/~bellman/nsc-puppet-utils.git. :-) (It doesn''t uniquify the contents, though, just plain concatenation.) /Bellman --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---