Forum: CFEngine Help Subject: Re: Class not being defined correctly Author: phnakarin Link to topic: https://cfengine.com/forum/read.php?3,23121,23122#msg-23122
Actually, the use of your regcmp/strcmp is correct, but the way CFE iterates array variables might create a loop in your check_user() bundle some how, leading to the unexpected result. Is it possible to getindice() before passing to the bundle such the following; By this approach, we can ensure that CFE would use those values only once in the bundle. ### I haven't tried the code, just assume that it should work ### body common control { bundlesequence => { "test" }; } bundle agent test { vars: "users" string => "Test User 1"; "users" string => "123"; "users" string => "dba"; "users" string => "/home/testuser1"; "users" string => "/bin/bash"; "users" string => "false"; "users" string => "false"; "users" string => "Test User 2"; "users" string => "124"; "users" string => "dba"; "users" string => "/home/testuser2"; "users" string => "/bin/bash"; "users" string => "true"; "users" string => "false"; ### getindice() here "index" slist => getindices("test.users"); methods: ### then pass to the bundle "any" usebundle => check_user("$(index)","$(users[$(index)])"); } ### adapt the bundle a bit bundle agent check_user(user,status) { # vars: # # "index" slist => getindices("$(user)"); classes: #"valid_user" expression => regcmp("true","$($(user)[$(index)])"); "valid_user" expression => strcmp("true","$(status)"); reports: valid_user:: "USER: $(user) is showing up as valid with a status of $(status)"; !valid_user:: "USER: $(user) is showing up as invalid with a status of $(status)"; } Cheers, --Nakarin _______________________________________________ Help-cfengine mailing list Help-cfengine@cfengine.org https://cfengine.org/mailman/listinfo/help-cfengine