On Tue, Jan 11, 2011 at 11:52:11AM -0500, [email protected] wrote:
>Forum: Cfengine Help
>Subject: Re: Random variable persistence problem -- crontab randomization
>Author: mark
>Link to topic: https://cfengine.com/forum/read.php?3,20077,20078#msg-20078
>
>Jennifer,
>
>take care over this. Are you sure you want a "random time"? This is a
>commonly (ab)used phrase. What people usually want to do is the spread the
>times out evenly over an interval in a predictable way. A random time could
>have all hosts changing their behaviour all of the time, and might not spread
>out the numbers at all.
>
>What the splaytime does in Cfengine is to "hash" hosts over an interval of
>time so that as few hosts collide as possible and times are distributed
>evenly over the interval. That is not at all random, but it maps each host to
>a very specific time (whose value you don't particularly care about).
I just realized that I had to solve a similar problem. I have two
package hosts for my clients, and I wanted to evenly, but
consistantly/reproduceably spread the load between them.
I did it like this (editied for brevity):
bundle yum {
vars:
# Use CF to generate a hash of the HOSTNAME env variable.
# Could also use IP addresses, or ${sys.fqhost}, I suppose.
"hostname_hash" string => hash(getenv("HOSTNAME","40"),'md5');
# Since CF doens't provide string manipulation functions, do it
# in shell/perl. I'd rather not have to, but there's other option
# Basically, take the MD5 hash, and check if the LSB is 0 or 1.
# Based on the result, choose one of two hostnames.
"yum_server" string => execresult("/bin/echo ${hostname_hash} |
/bin/cut -c -3 | perl -e '$a=(hex(<>)%2) ? qq(pkg_srv1) : qq(pkg_srv2); print
$a'","useshell");
files:
# Fetch the file. update() is a custom copy_from body that
# automatically handles the server/path locations on the policy server.
"/etc/yum.repos.d/local_packages.repo"
copy_from =>
update("/etc/yum.repos.d/local_packages.repo-${yum_server}");
}
--
Jesse Becker
NHGRI Linux support (Digicon Contractor)
_______________________________________________
Help-cfengine mailing list
[email protected]
https://cfengine.org/mailman/listinfo/help-cfengine