Here''s a problem I didn''t really think about for so long. I''m kind of hoping somebody solved it already :) I''m working on a "geoip" module that among other things, installs a cronjob to update the geoip databases periodically. Now the cronjob is just a plain file resource that puppet drops into ''/etc/cron.d/''. == Problem = Doing that on 50 machines will result in all of them trying to download the geoip dbs at the same time. == Possible solutions = 1) prepend the cronjob task with "perl -e ''sleep rand 3600'' ; " or equivalent 2) have a puppet template "randomize" the cron minute, hour and eventually day. == Question = About 2), how do I randomize a template and have puppet avoid replacing it whenever there''s a new run? Is there a way to do this? -- Cosimo -- 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 01/05/2011 12:49 PM, Cosimo Streppone wrote:> Here''s a problem I didn''t really think about for > so long. I''m kind of hoping somebody solved it > already :) > > I''m working on a "geoip" module that among other > things, installs a cronjob to update the geoip > databases periodically. > > Now the cronjob is just a plain file resource > that puppet drops into ''/etc/cron.d/''. > > == Problem => > Doing that on 50 machines will result > in all of them trying to download the geoip dbs > at the same time. > > == Possible solutions => > 1) prepend the cronjob task with "perl -e ''sleep rand 3600'' ; " > or equivalent > > 2) have a puppet template "randomize" the cron minute, hour and > eventually day. > > == Question => > About 2), how do I randomize a template and have puppet avoid > replacing it whenever there''s a new run? > > Is there a way to do this? >Yes. Ideally: http://docs.puppetlabs.com/references/stable/function.html#fqdnrand -- 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 Wed, 05 Jan 2011 12:50:41 +0100, Felix Frank <felix.frank@alumni.tu-berlin.de> wrote:> On 01/05/2011 12:49 PM, Cosimo Streppone wrote: >> >> About 2), how do I randomize a template and have puppet avoid >> replacing it whenever there''s a new run? >> >> Is there a way to do this? > > Yes. Ideally: > > http://docs.puppetlabs.com/references/stable/function.html#fqdnrandYes, that''s *exactly* what I need. Great stuff, thanks! -- Cosimo -- 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.
For something that''s a bit more generic, you can also just use $RANDOM with sleep. $RANDOM returns between 0 and 32k as a value, and you can use a divider to reduce it. For example, I use ''sleep $(($RANDOM/10)) && do_heavy_stuff'' to randomize the start of a heavy job out across just under a hour. BR. RuneSt. On 5 Jan, 12:58, "Cosimo Streppone" <cos...@streppone.it> wrote:> On Wed, 05 Jan 2011 12:50:41 +0100, Felix Frank > > <felix.fr...@alumni.tu-berlin.de> wrote: > > On 01/05/2011 12:49 PM, Cosimo Streppone wrote: > > >> About 2), how do I randomize a template and have puppet avoid > >> replacing it whenever there''s a new run? > > >> Is there a way to do this? > > > Yes. Ideally: > > >http://docs.puppetlabs.com/references/stable/function.html#fqdnrand > > Yes, that''s *exactly* what I need. > > Great stuff, thanks! > > -- > Cosimo-- 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 Wed, 05 Jan 2011 13:59:29 +0100, Rune Stensø <rune.stensoe@gmail.com> wrote:> For something that''s a bit more generic, you can also just use $RANDOM > with sleep. $RANDOM returns between 0 and 32k as a value, and you can > use a divider to reduce it. > For example, I use ''sleep $(($RANDOM/10)) && do_heavy_stuff'' to > randomize the start of a heavy job out across just under a hour.Learning something new every day :) Very useful indeed. Thanks, -- Cosimo -- 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.
Am Wed, 05 Jan 2011 04:59:29 -0800 schrieb Rune Stensø:> For something that''s a bit more generic, you can also just use $RANDOM > with sleep. $RANDOM returns between 0 and 32k as a value, and you can > use a divider to reduce it. > For example, I use ''sleep $(($RANDOM/10)) && do_heavy_stuff'' to > randomize the start of a heavy job out across just under a hour. >$RANDOM is "bash''ism". it''s not available to all shells out there. - Thomas -- 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 Wed, Jan 5, 2011 at 7:00 AM, Thomas Mueller <thomas@chaschperli.ch>wrote:> Am Wed, 05 Jan 2011 04:59:29 -0800 schrieb Rune Stensø: > > > For something that''s a bit more generic, you can also just use $RANDOM > > with sleep. $RANDOM returns between 0 and 32k as a value, and you can > > use a divider to reduce it. > > For example, I use ''sleep $(($RANDOM/10)) && do_heavy_stuff'' to > > randomize the start of a heavy job out across just under a hour. > > > > $RANDOM is "bash''ism". it''s not available to all shells out there. > >Right. And if you do this: #! /bin/bash sleep $((RANDOM % 600)) exec puppet ... Using modulus rather than division is probably better here. This sleeps somewhere from zero to 10 minutes. Note also, you don''t need to use $RANDOM inside $(()) in bash. -- Jeff McCune http://www.puppetlabs.com/ -- 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.