Hi! Is it possible to add a new element to an array inside puppet manifest ? Something like ruby''s array.push(''new_element'') ? -- Best regards, Sergey Arlashin -- 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.
Daniele Sluijters
2013-Oct-21 21:49 UTC
[Puppet Users] Re: Puppet 3.2: add element to array
HI, It should be possible to do something like this: $users = [a,b,c] $users += [d,e] Or, $users = [[a,b,c] [d,e]] etc. Perhaps a better question, what is it you''re trying to do, exactly, that you need this? -- Daniele Sluijters On Monday, 21 October 2013 20:21:18 UTC+2, Sergey Arlashin wrote:> > Hi! > Is it possible to add a new element to an array inside puppet manifest ? > Something like ruby''s array.push(''new_element'') ? > > -- > Best regards, > Sergey Arlashin-- 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 Monday, October 21, 2013 1:21:18 PM UTC-5, Sergey Arlashin wrote:> > Hi! > Is it possible to add a new element to an array inside puppet manifest ? > Something like ruby''s array.push(''new_element'') ? > >No, it isn''t. It is a fundamental principle of Puppet that variables'' values cannot be changed once set. In particular, the += operator Daniele refers to does not do quite what she supposes: it sets the initial value of a local variable by appending data to the value of a *separate* variable of the same name at top scope, node scope, or a parent scope (http://docs.puppetlabs.com/puppet/3/reference/lang_variables.html#appending-assignment). That may be sufficient for your needs, but it is not what you actually asked, and I would not expect the code Daniele presented to work. 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.
It is possible in a lot of puppet versions but it is a bug and might get fixed. $a = [1,2] $a[2]=3 notice($a) On 22 October 2013 15:20, jcbollinger <John.Bollinger@stjude.org> wrote:> > > On Monday, October 21, 2013 1:21:18 PM UTC-5, Sergey Arlashin wrote: >> >> Hi! >> Is it possible to add a new element to an array inside puppet manifest ? >> Something like ruby''s array.push(''new_element'') ? >> >> > > No, it isn''t. It is a fundamental principle of Puppet that variables'' > values cannot be changed once set. > > In particular, the += operator Daniele refers to does not do quite what > she supposes: it sets the initial value of a local variable by appending > data to the value of a *separate* variable of the same name at top scope, > node scope, or a parent scope ( > http://docs.puppetlabs.com/puppet/3/reference/lang_variables.html#appending-assignment). > That may be sufficient for your needs, but it is not what you actually > asked, and I would not expect the code Daniele presented to work. > > > 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. >-- Erik Dalén -- 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.
Henrik Lindberg
2013-Oct-25 00:07 UTC
Re: [Puppet Users] Re: Puppet 3.2: add element to array
On 2013-24-10 11:19, Erik Dalén wrote:> It is possible in a lot of puppet versions but it is a bug and might get > fixed. > > $a = [1,2] > $a[2]=3 > notice($a) > >It is a bug that is planned to be fixed in Puppet 4. (It cannot be changed in the 3.x series as it would potentially be a breaking change). Yes, we are serious about semver :-) The future parser (and hence also in Puppet 4) allows concatenation of array (and merge of hash) to a *new* variable otherwise variables are strictly immutable. Regards - henrik> On 22 October 2013 15:20, jcbollinger <John.Bollinger@stjude.org > <mailto:John.Bollinger@stjude.org>> wrote: > > > > On Monday, October 21, 2013 1:21:18 PM UTC-5, Sergey Arlashin wrote: > > Hi! > Is it possible to add a new element to an array inside puppet > manifest ? Something like ruby''s array.push(''new_element'') ? > > > > No, it isn''t. It is a fundamental principle of Puppet that > variables'' values cannot be changed once set.. > > In particular, the += operator Daniele refers to does not do quite > what she supposes: it sets the initial value of a local variable by > appending data to the value of a /separate/ variable of the same > name at top scope, node scope, or a parent scope > (http://docs.puppetlabs.com/puppet/3/reference/lang_variables.html#appending-assignment). > That may be sufficient for your needs, but it is not what you > actually asked, and I would not expect the code Daniele presented to > work. > > > 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 > <mailto:puppet-users%2Bunsubscribe@googlegroups.com>. > To post to this group, send email to puppet-users@googlegroups.com > <mailto: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. > > > > > -- > Erik Dalén > > -- > 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.-- 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.