This function is only available in CFEngine Enterprise.

Prototype: hostswithgroup(group_name, field)

Return type: slist

Description: Returns a list from the CFEngine Database with the information field of all hosts sharing the group group_name.

On CFEngine Enterprise, this hub function can be used to return a list of hostnames, ip-addresses or public key SHAs of hosts that are from the same group. It works very similarly as its twin hostswithclass().

Arguments:

  • group_name: string - Group name to look for - in the range: [a-zA-Z0-9_]+
  • field: - Type of return value desired - one of
    • name
    • address
    • hostkey

Example:

code
bundle agent debian_hosts
{
vars:

  am_policy_hub::
    "host_list" slist => hostswithgroup( "Linux", "name" );

files:
  am_policy_hub::
    "/tmp/master_config.cfg"
         edit_line => insert_lines("host=$(host_list)"),
            create => "true";
}

History: Was introduced in 3.26.0

See also: hostswithclass()