Forum: CFEngine Help
Subject: Do a single DNS lookup
Author: sauer
Link to topic: https://cfengine.com/forum/read.php?3,23813,23813#msg-23813

So, our cfengine server layout basically has a single master, and then 
secondary servers which are geographically distributed.  The secondaries pull 
the master policy from the central system, and then systems in each specific 
geographic location pull the config from their local secondary.  In order to 
facilitate this, I have a single DNS entry which, when looked up, returns the 
IP of the local server first, and then the others later.  This makes my 
configuration way simpler, as I just say "copy config from thesource.mydomain", 
and DNS takes care of the rest.

Except that it doesn't work that way.  It seems that each new promise which 
references thesource iterates through the values returned in DNS.  I'm pretty 
sure this is a side effect of how the OS's resolver works, but I'm not positive 
that it's not Cfengine instead.  I therefore have two questions:

In the long term, i think it'd be handy to be able to configure how round-robin 
DNS entries are handled.  I'd like to see a common control parameter which 
selects between "first", "random" and "round-robin" to control which IP 
cfengine uses if the resolver provides multiple IPs for a name.  I'll submit a 
feature request shortly, but first I wonder if it's Cfengine rotating through 
the results, or if it's the OS (this seems to happen on more than just Linux).

In the short term, I'd like a suggestion as to how I can just get an IP into a 
variable once and use that for the rest of the evaluation.  Avoid the 
temptation to suggest something simple like this:

vars:
   "master_ip"   string => host2ip( "thesource" );
   "master_host" string => ip2host( "$(master_ip)" );


Because that tosses out a bunch of warnings about variables being redefined 
(due to the host2ip function returning different values on later runs).  But 
what about defining a class?

vars:
  !g_havehost::
    "master_ip"   string => host2ip( "thesource" );
    "master_host" string => ip2host( "$(master_ip)" );

classes:
  "g_havehost"      expression => regcmp(".+", "cfmaster_host");


Close, but no cigar.  I get all sorts of weird behavior depending on the 
bundlesequence used.  Technically, the first one does work, but I really don't 
like having warnings spit out - not only because they're indicative of a 
less-than-elegant solution, but also because they obscure more important 
warnings by training people to just ignore warnings.

_______________________________________________
Help-cfengine mailing list
Help-cfengine@cfengine.org
https://cfengine.org/mailman/listinfo/help-cfengine

Reply via email to