Hi, Can you round in variable assignment expressions? I would like to be able to set $my_var = floor(::processorcount * 0.8) Cheers, Tom -- 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.
On 2011-11-15 07:24 , Tom Hall wrote:> Hi, > > Can you round in variable assignment expressions? > > I would like to be able to set > > $my_var = floor(::processorcount * 0.8) > > Cheers, > Tom >That should work just fine as long as you define an rvalue function called ''floor''. There should be a bunch of good examples of how to do this in the stdlib[0] repo in lib/puppet/parser/functions. [0] https://github.com/puppetlabs/puppetlabs-stdlib/ -- Jacob Helwig http://about.me/jhelwig
On 15 November 2011 16:57, Jacob Helwig <jacob@puppetlabs.com> wrote:> On 2011-11-15 07:24 , Tom Hall wrote: > > Hi, > > > > Can you round in variable assignment expressions? > > > > I would like to be able to set > > > > $my_var = floor(::processorcount * 0.8) > > > > Cheers, > > Tom > > > > That should work just fine as long as you define an rvalue function > called ''floor''. There should be a bunch of good examples of how to do > this in the stdlib[0] repo in lib/puppet/parser/functions. > > [0] https://github.com/puppetlabs/puppetlabs-stdlib/I suspect it won''t be a trivial or generic function. Puppet won''t be able to do the initial arithmetic within the braces because $::processorcount is a string. So you might end up with something like "multiply_floor($::processorcount, 0.8)" or "floor(str2int($::processorcount) * 0.8)". Alternatively the cheap and hacky approach: $foo = inline_template("<%= (processorcount.to_i * 0.8).floor -%>") -- 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.
> Alternatively the cheap and hacky approach: > $foo = inline_template("<%= (processorcount.to_i * 0.8).floor -%>")That looks direct and sexy to me. -- 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.