Forum: Cfengine Help Subject: Re: Are case-insensitive classes possible? Author: babudro Link to topic: https://cfengine.com/forum/read.php?3,19067,19094#msg-19094
zzamboni Wrote: ------------------------------------------------------- > "lchostname" string => execresult("hostname | tr '[:upper:]' '[:lower:]'", > "useshell"); > classes: > "hostname_is_lc" expression => strcmp("$(sys.fqdn)", "$(lchostname)"); > commands: > !hostname_is_lc:: > "hostname $(lchostname)"; > files: > # Make the change permanent, add as needed for other versions of Unix/Linux I thought I would implement this idea and in so doing gained some insight I thought I would share here: 1. hostname_is_lc should be hostname_not_lc and should be a negated class, otherwise it will execute many times you do not want it to. 2. The final edits to the /etc/hosts or /etc/myname file aren't needed if one has a promise to maintain this file already. 3. execresult doesn't work unless you specify paths (e.g., "/bin/hostname | /usr/bin/tr ..."). 4. Cfengine docs for execresult say not to do this: Note: you should never use this function to execute comands that make changes to the system, or perform lengthy computations. Such an operation is beyond cfengine's ability to guarantee convergence, and on multiple passes and during syntax verification, these function calls are executed resulting in system changes that are `covert'. Calls to execresult should be for discovery and information extraction only. My solution instead, if/until Cfengine implements the feature request to make host/domain names case-insensitive, is to set my own variables: # (sys.host) is sometimes the FQDN and other times the host name only. # Also, we want to be sure host name & domain name are always lower-case, so we set our own variables: # "short_hostname" string => execresult("/bin/hostname -s | /usr/bin/tr '[:upper:]' '[:lower:]'","useshell"); "long_hostname" string => execresult("/bin/hostname -f | /usr/bin/tr '[:upper:]' '[:lower:]'", "useshell"); # ... in a global "common" bundle and then i just use those names instead of $(sys.name) and $(sys.fqdn). This turns out to be more reliable anyway because for some reason (that I haven't taken the time to identify) I have seen this odd behaviour: $ hostname rhtest2.irving.com $ hostname -s rhtest2 Just one of my dev hosts does this, and it causes the $(sys.host) variable in Cfengine to show the FQDN. So the above variables solve two problems at once. _______________________________________________ Help-cfengine mailing list Help-cfengine@cfengine.org https://cfengine.org/mailman/listinfo/help-cfengine