Forum: CFEngine Help
Subject: Re: classes not working in vars?
Author: ipesin
Link to topic: https://cfengine.com/forum/read.php?3,25293,26337#msg-26337

Hi!

Sorry for reviving the old topic but bumped into similar issue - defining a 
class in vars: section. Basically, the reason is that we want to set variable 
to output of a command, which is heavy to execute. We found that:

vars:
  "someresults" string => execresult("ls -l /tmp", "useshell");

forks 7 times, which clearly might cause quite a load. So the idea was to 
reduce amount of invocations and we tried this one:


vars:

   !dontrun::
     "someresults" string => execresult("ls -l /tmp", "useshell"), classes => 
always("dontrun");

This reduced number of forks to 3. Which was promising, so we went further and 
made following code:

        vars:

        "singlerun" string => "temporary variable for single run", classes => 
always("singlerun");

        singlerun.!dontrun::
            "testvar" string => execresult("/bin/ls -l /", "useshell"),
                classes => always("dontrun");

This gave us exactly one invocation of "ls" in this case. 

All of that worked on CFEngine Core 3.3. When we tried to run same code on Core 
3.2.4 it appeared that although it runs only once, "dontrun" class is not 
visible outside vars: section.

So, this is to say that you can define classes in vars:

Also, would be great to understand the process of vars: and classes: evaluation 
at least in brush strokes. I wasn't able to find it anywhere, unfortunately.

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

Reply via email to