Prototype: getusers(exclude_names, exclude_ids)

Return type: slist

Description: Returns a list of all users defined, except those names in the comma separated string of exclude_names and the comma separated string of uids in exclude_ids


  • exclude_names: string - Comma separated list of User names - in the range: .*
  • exclude_ids: string - Comma separated list of UserID numbers - in the range: .*


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

bundle agent example

      # The getusers function takes two filtering arguments: exclude_names and
      # exclude_ids, both a comma separated list of usernames and user IDs
      # respectively.

      # To get users with a uid 1000 and greater we generate a list of uids from
      # 0 to 999 and convert it into a comma separated string used to filter the
      # list of users.

        slist => getusers( "", join( ",", expandrange( "[0-999]", 1 ) ) );

      # Here we get a list of users except usernames nfsnobody and vagrant as
      # well as any users with uid 8 or 9

        slist => getusers( "nfsnobody,vagrant", "8,9" );

      # Here we get a list of all users by not filtering any
      "allusers" slist => getusers("","");
      "root_list" slist => { "root" };
      # this will get just the root users out of the full user list
      "justroot" slist => intersection(allusers, root_list);

      "Found just the root user: $(justroot)";


R: Found just the root user: root


  • This function is currently only available on Unix-like systems.
  • This function will return both local and remote (for example, users defined in an external directory like LDAP) users on a system.


  • Introduced in CFEngine 3.1.0b1, CFEngine Nova/Enterprise 2.0.0b1 (2010).

See also: getuserinfo(), users.