Nick,

It works exactly as you have it. That is, pipe (|) is the proper OR and dot (.) 
is the proper AND. You can also use an ampersand (&) for AND, although I do 
prefer dot.

It looks to me that reason you're having a problem is that all of your 
variables need to be defined, regardless of wether or not the later class will 
ever end up getting defined.

This is a prototype of your example, but with shorter names:

bundle agent test {

vars:

  "v1" string => "1";
  "v2" string => "2";

classes:

  "a_1" expression => "any";
  "b_1" expression => "any";
  "c_1_2" expression => "any";

reports:

  cfengine_3::
    "foo" ifvarclass => "(a_$(v1).b_$(v1))|(a_$(v1).!c_$(v1)_$(v2))";

}

Play with this by commenting out various combinations of a_1, b_1 and c_1_2. 
You'll see that each produces exactly what you would expect.

However, if at any time "v2" does not exist, wether or not c_1_2 is defined 
then the report will not happen.

Going back to your example, I would assume that $(userlist) always exists, but 
$(gid) does not (or perhaps it is in a different bundle and not scoped 
correctly). In order to guarantee that $(gid) exists you should declare it (or 
both) early in this bundle with some bogus value and flag it as redefinable.

E.g.:

vars:
  "gid" string => "UNDEF", policy => "free";

Hope this helps.

-- 
Brian

On Mar 3, 2012, at 12:10 PM, Nick Anderson wrote:

> I am trying to use ifvarclass to restrict a file edit
> 
> This is the construction I am trying to use but i cant seem to get it to
> evaluate.
> ifvarclass =>
> "(groupname_defined_$(userlist).allow_non_unique_gid_$(userlist))|(groupname_defined_$(userlist).!gid_in_use_$(userlist)_$(gid))";
> 
> To do the edit I need both groupname_defined_$(userlist) and
> allow_non_unique_gid_$(userlist)
> or
> groupname_defined_$(userlist) but not allow_non_unique_gid_$(userlist)
> 
> I see the or and not functions, but no and function. I am not quite sure
> how to define this can someone help me express this class restriction
> that I need?
> 
> Maybe I need to join those two sets with classes type promises so I can
> do an ifvarclass => or?
> 
> -- 
> Nick Anderson <n...@cmdln.org>
> _______________________________________________
> Help-cfengine mailing list
> Help-cfengine@cfengine.org
> https://cfengine.org/mailman/listinfo/help-cfengine

Attachment: smime.p7s
Description: S/MIME cryptographic signature

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

Reply via email to