Hello all,

Assuming the following :

body common control
{
   bundlesequence  => { "groups" };
}

bundle agent groups
{
vars:
   "gid"                int => 0;
   "server_list"        int => 1;

   "group[avatar][$(gid)]"              string =>  "500";
   "group[avatar][$(server_list)]"      string => "xxx|yyy";

   "group[gbadnum][$(gid)]"             string => "110";
   "group[gbadnum][$(server_list)]"     string => "xxx|yyy";

   "group1[avatar][$(gid)]"             string =>  "600";
   "group1[avatar][$(server_list)]"     string => "xxx|yyy";

   "group1[gbadnum][$(gid)]"            string => "500";
   "group1[gbadnum][$(server_list)]"    string => "xxx|yyy";

   "g_list"                             slist  => { "group", "group1" };
   "group_names"                        slist  => getindices("group");
   "group1_names"                       slist  => getindices("group1");

methods:
      "add_group_if"    usebundle => do_add_group_if("$(group_names)", 
"$(group[$(group_names)][$(gid)])"),
                        ifvarclass => 
"$(group[$(group_names)][$(server_list)])";

      "add_group_if"    usebundle => do_add_group_if("$(group1_names)", 
"$(group1[$(group1_names)][$(gid)])"),
                        ifvarclass => 
"$(group1[$(group1_names)][$(server_list)])";

}

bundle agent do_add_group_if(groupname, group_id)
{
classes:
      "group_exist"     expression => groupexists("$(groupname)");
      "gid_exist"       expression => groupexists("$(group_id)");

commands:
   !group_exist.!gid_exist::
   "/bin/echo addgroup -g $(group_id) $(groupname)",
      classes    => if_ok("group_created");

reports:
   cfengine_3::
       "group $(groupname) gid $(group_id)";
   cfengine_3.(!group_exist.!group_created)::
      "The $(groupname) group could not be created, the gid $(group_id) already 
in use";
   cfengine_3.group_created::
      "The $(groupname) group created with gid $(group_id)";
}

body classes if_ok(c)
{
   promise_repaired => { "$(c)" };
   promise_kept => { "$(c)" };
}



And the following output from the command  cf-agent -K -f ./unit_group_test.cf

R: group gbadnum gid 110
R: The gbadnum group could not be created, the gid 110 already in use
R: group avatar gid 500
R: The avatar group could not be created, the gid 500 already in use
Q: ".../bin/echo addgr": addgroup -g 600 avatar
I: Last 1 QUOTEed lines were generated by promiser "/bin/echo addgroup -g 600 
avatar"
I: Made in version 'not specified' of './unit_group_test.cf' near line 45
R: group avatar gid 600
R: The avatar group created with gid 600
R: group gbadnum gid 500
R: The gbadnum group created with gid 500


Now the problem:
The class group_created is defined when the avatar group is created (the echo 
command from the Q).
Next the group gbadnum comes in with the gid 500 and the report should be
R: The gbadnum group could not be created, the gid 500 already in use
Like it was for the first attempt to create the group avatar and the gid 500
But instead it reports the group was created, although the echo command never 
got executed.  The only explanation for me is that the class group_created that 
was defined in the previous call to the bundle is still active when the bundle 
is called again for the group gbadnum and gid 500.



So my question is when is a class public versus private?

>From the above it seems to be private if declared in a classes section of a 
>bundle and public otherwise.  Is this correct?

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

Reply via email to