Forum: CFEngine Help
Subject: Re: create class which is a superset of another class
Author: zzamboni
Link to topic: https://cfengine.com/forum/read.php?3,24736,24749#msg-24749
> Let's say I want to create a class which contains
> both classes:
>
> "agents_and_master" or => {
> "agent01" , "agent02" , "agent03" , "master01" };
>
> Is there a way to create a class which contains
> multiple other classes?
Just use the class names in an "or" expression, like this:
"agents_and_master" or => { "agents", "master" };
The new class will be defined on all hosts that belong to either the first
class ("agents") OR the second one ("master").
> In this case I am only dealing with two classes,
> so I could use an OR expression, when selecting
> the hosts I want, eg.
>
> files:
> agents|master::
Or if you have defined agents_and_master as before, you could use:
agents_and_master::
...
> But it seems to me that OR will not work with more
> than two choices and in reality I want to merge
> more than two classes. I guess I could use an AND
> in that case?
Why would it not work? OR is a logical operation, it would work on any number
of classes:
"some_class" or => { "agents", "master", "dns_server", "web_server",
"suse_9" };
You can use any number and any kind of classes (like I did with "suse_9", which
would be a hard class defined on SuSE 9 machines).
AND is a different boolean operation. If you use AND, then the new class will
be defined only on machines in which all the classes listed in the expression
are set. For example:
"suse9_agents" and => { "agents", "sure_9" };
This class would be defined only on machines in which both "agents" AND
"suse_9" are defined (arguably, agents running SuSE 9). And just like OR, you
can use AND with as many classes as you want.
> And I would like to do something fancier than
> naming all the hosts in a class. Something like:
>
> "agents" expression => regcmp( "ag.*" ,
> "${sys.host}");
>
> but I have two hosts that would match that
> expression and I want to exclude them. Let's say
> they are agent041 and agent042.
You could do this like Nick suggested, by explicitly excluding them, with
something like this:
"agents" expression => and(regcmp( "ag.*", "$(sys.host)" ), not("agent041"),
not("agent042"));
_______________________________________________
Help-cfengine mailing list
[email protected]
https://cfengine.org/mailman/listinfo/help-cfengine