Douglas Garstang
2011-Sep-27 22:12 UTC
[Puppet Users] Increment variable each time a definition is called.
I want to set a variable in a class, and then increment the value of that variable each time a definition is called. Since I have to qualify the variable in the definition, like so: $platform::proxy::config::ssl_port_start I tried this: $platform::proxy::config::ssl_port_start $platform::proxy::config::ssl_port_start + 1 but then puppet complains: "Cannot assign to variables in other namespaces at..." .... and since I have to qualify the original variable.... ugh.... how can I do this? Doug -- 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.
Dan Bode
2011-Sep-27 22:20 UTC
Re: [Puppet Users] Increment variable each time a definition is called.
I can think of something really hacky that I don''t recommend for production, it could be ok for debugging purposes. notice(inline_template( ''<%= $dangerous_counter = $dangerous_counter || 0; $dangerous_counter = $dangerous_counter + 1 %>'' )) will create a global variable in Ruby, I have a feeling that this will increment for all nodes if you are running a master though. On Tue, Sep 27, 2011 at 3:12 PM, Douglas Garstang <doug.garstang@gmail.com>wrote:> I want to set a variable in a class, and then increment the value of > that variable each time a definition is called. Since I have to > qualify the variable in the definition, like so: > > $platform::proxy::config::ssl_port_start > > I tried this: > > $platform::proxy::config::ssl_port_start > $platform::proxy::config::ssl_port_start + 1 > > but then puppet complains: > > "Cannot assign to variables in other namespaces at..." > > .... and since I have to qualify the original variable.... ugh.... how > can I do this? > > Doug > > -- > 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.
Douglas Garstang
2011-Sep-27 22:25 UTC
Re: [Puppet Users] Increment variable each time a definition is called.
On Tue, Sep 27, 2011 at 3:20 PM, Dan Bode <dan@puppetlabs.com> wrote:> I can think of something really hacky that I don''t recommend for production, > it could be ok for debugging purposes. > > notice(inline_template( ''<%= $dangerous_counter = $dangerous_counter || 0; > $dangerous_counter = $dangerous_counter + 1 %>'' )) > > will create a global variable in Ruby, I have a feeling that this will > increment for all nodes if you are running a master though.I hope that''s not the only way. What I''m trying to do here isn''t that unusual. I have an several instances of an application running, each with different port numbers. The definition sets the values for the instance, but rather than listing the port numbers, which can cause copy and paste errors, I wanted to have the port numbers auto incremented from a base value. Doug. -- 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.
Daniel Pittman
2011-Sep-27 22:40 UTC
Re: [Puppet Users] Increment variable each time a definition is called.
On Tue, Sep 27, 2011 at 15:20, Dan Bode <dan@puppetlabs.com> wrote:> I can think of something really hacky that I don''t recommend for production, > it could be ok for debugging purposes.Yeah, this is *totally* not a sane thing to do. Really not sane. Find a better way to solve your problem. That said, you can also use defined types recursively in Puppet: define foo() { if ($name == 0) { notice("done") } else { notice("bar is $name") $bar = $name - 1 foo { $bar: } } } foo { "4": } Daniel -- ⎋ Puppet Labs Developer – http://puppetlabs.com ♲ Made with 100 percent post-consumer electrons -- 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.
Jason Slagle
2011-Sep-27 22:55 UTC
Re: [Puppet Users] Increment variable each time a definition is called.
On Tue, 27 Sep 2011, Douglas Garstang wrote:> I hope that''s not the only way. What I''m trying to do here isn''t that > unusual. I have an several instances of an application running, each > with different port numbers. The definition sets the values for the > instance, but rather than listing the port numbers, which can cause > copy and paste errors, I wanted to have the port numbers auto > incremented from a base value.Call me crazy, but I''m not sure I see the "common use case" here. Puppet does not process a manifest top down (Well at least not in a way that you expect). At best I would expect these port numbers to change at every addition. At worst, I can see them changing every run. I presume you''re going to use these numbers elsewhere to configure some front end. I''m not sure you''d want it reloading your apache, etc all the time as the port numbers bounce around. If you REALLY wanted to do something like this, I might suggest you create a type, and define the namevar in such a way as to ensure you cannot have overlap. Jason -- Jason Slagle - RHCE5, VCP4 /"\ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . \ / ASCII Ribbon Campaign . X - NO HTML/RTF in e-mail . / \ - NO Word docs in e-mail . -- 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.
Douglas Garstang
2011-Sep-27 22:55 UTC
Re: [Puppet Users] Increment variable each time a definition is called.
On Tue, Sep 27, 2011 at 3:40 PM, Daniel Pittman <daniel@puppetlabs.com> wrote:> On Tue, Sep 27, 2011 at 15:20, Dan Bode <dan@puppetlabs.com> wrote: >> I can think of something really hacky that I don''t recommend for production, >> it could be ok for debugging purposes. > > Yeah, this is *totally* not a sane thing to do. Really not sane. > Find a better way to solve your problem. > > That said, you can also use defined types recursively in Puppet: > > define foo() { > if ($name == 0) { > notice("done") > } > else > { > notice("bar is $name") > $bar = $name - 1 > foo { $bar: } > } > } > > foo { "4": }Taking that one step further, I tried: define platform::proxy::instance ( $ssl_port ) { if ( $name == 0 ) { } else { $bar = $name - 1 $ssl_port = $ssl_port + 1 platform::proxy::instance { $bar: ssl_port => $ssl_port } } } platform::proxy::instance { 16: ssl_port => 8557; } However, this gives the error: Cannot reassign variable ssl_port at... *sigh* Doug. -- 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.
Douglas Garstang
2011-Sep-27 23:02 UTC
Re: [Puppet Users] Increment variable each time a definition is called.
On Tue, Sep 27, 2011 at 3:55 PM, Jason Slagle <raistlin@tacorp.net> wrote:> > > On Tue, 27 Sep 2011, Douglas Garstang wrote: > >> I hope that''s not the only way. What I''m trying to do here isn''t that >> unusual. I have an several instances of an application running, each >> with different port numbers. The definition sets the values for the >> instance, but rather than listing the port numbers, which can cause >> copy and paste errors, I wanted to have the port numbers auto >> incremented from a base value. > > Call me crazy, but I''m not sure I see the "common use case" here. Puppet > does not process a manifest top down (Well at least not in a way that you > expect).How''s that relevant? I''m not declaring various resource types. I''m either calling definitions (in which case I''m pretty sure it does them in a top-down order), or doing it programatically.> > At best I would expect these port numbers to change at every addition. At > worst, I can see them changing every run. I presume you''re going to use > these numbers elsewhere to configure some front end. I''m not sure you''d > want it reloading your apache, etc all the time as the port numbers bounce > around.I don''t follow you. Why would the port numbers change around if they where programatically generated? Not that I can do that anyway, as you''ll see in a followup post, as I cant reassign variables. Doug. -- 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.
Douglas Garstang
2011-Sep-27 23:07 UTC
Re: [Puppet Users] Increment variable each time a definition is called.
On Tue, Sep 27, 2011 at 3:55 PM, Douglas Garstang <doug.garstang@gmail.com> wrote:> On Tue, Sep 27, 2011 at 3:40 PM, Daniel Pittman <daniel@puppetlabs.com> wrote: >> On Tue, Sep 27, 2011 at 15:20, Dan Bode <dan@puppetlabs.com> wrote: >>> I can think of something really hacky that I don''t recommend for production, >>> it could be ok for debugging purposes. >> >> Yeah, this is *totally* not a sane thing to do. Really not sane. >> Find a better way to solve your problem. >> >> That said, you can also use defined types recursively in Puppet: >> >> define foo() { >> if ($name == 0) { >> notice("done") >> } >> else >> { >> notice("bar is $name") >> $bar = $name - 1 >> foo { $bar: } >> } >> } >> >> foo { "4": } > > Taking that one step further, I tried: > > > define platform::proxy::instance ( $ssl_port ) { > if ( $name == 0 ) { > } else { > $bar = $name - 1 > $ssl_port = $ssl_port + 1 > platform::proxy::instance { $bar: ssl_port => $ssl_port } > } > } > > platform::proxy::instance { 16: ssl_port => 8557; } > > However, this gives the error: > > Cannot reassign variable ssl_port at... > > *sigh* > > Doug. >Got it... define platform::proxy::instance ( $ssl_port ) { if ( $name == 0 ) { } else { $bar = $name - 1 $ssl_port_in = $ssl_port + 1 notice ("ssl_port = $ssl_port_in") platform::proxy::instance { $bar: ssl_port => $ssl_port_in } } } -- 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.
Jurgen
2013-Aug-07 10:52 UTC
Re: [Puppet Users] Increment variable each time a definition is called.
Douglas Garstang <doug.garstang <at> gmail.com> writes:>how can I do this?you ever find a way to do this? I am looking for the same thing. -- 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.
jcbollinger
2013-Aug-07 12:51 UTC
Re: [Puppet Users] Increment variable each time a definition is called.
On Wednesday, August 7, 2013 5:52:06 AM UTC-5, Jurgen wrote:> > Douglas Garstang <doug.garstang <at> gmail.com> writes: > > >how can I do this? > > > > you ever find a way to do this? I am looking for the same thing. > >The values of Puppet variables cannot be changed once set. If you somehow found a way around that restriction then it would necessarily involve manipulating a Puppet bug, therefore you would have no guarantee that it would continue to work if you change anything. Just don''t do it. Instead, take a step back and consider the larger objective you are trying to achieve, rather than focusing on this particular, unviable, approach to achieving it. If you explain, then we may be able to help devise an alternative approach. 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.