Forum: CFEngine Help
Subject: Re: Class not being defined correctly
Author: zzamboni
Link to topic: https://cfengine.com/forum/read.php?3,23121,23124#msg-23124

The way Nakarin suggests would work. Alternatively, you can use your bundle as 
is, but you need to include the username in each class name. Remember that 
cfengine iterates over your "classes:" statement for every single user *before* 
going to the reports: section, so the class "valid_user" will only contain the 
value corresponding to the last user in the iteration. You need something like 
this:

bundle agent check_user(user)
{

vars:

 "index" slist => getindices("$(user)");
 "cindex[$(index)]" string => canonify("$(index)");

classes:

 "valid_user_$(cindex[$(index)])" expression => 
strcmp("true","$($(user)[$(index)])");

reports:
  "USER: $(index) is showing up as valid with a status of $($(user)[$(index)])"
      ifvarclass => "valid_user_$(cindex[$(index)])";

  "USER: $(index) is showing up as invalid with a status of 
$($(user)[$(index)])"
      ifvarclass => "!valid_user_$(cindex[$(index)])";


Note that I'm defining another array containing the canonified usernames, just 
in case (usernames should be pretty canonical, but you never know) and then 
using those values as part of the classnames, to be able to decide on each 
individual user.

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

Reply via email to