Working with host groups

A host group acts as a template for common host settings. Instead of defining the settings individually for each host, use host groups to define common settings once and apply them to multiple hosts.

Host group settings and nested host groups

A host group can define many settings for hosts, such as lifecycle environment, content view, or Ansible roles that are available to the hosts.

When you change the settings of an existing host group, the new settings do not propagate to the hosts assigned to the host group. Only Puppet class settings get updated on hosts after you change them in the host group.

You can create a hierarchy of host groups. Aim to have one base level host group that represents all hosts in your organization and provides general settings, and then nested groups that provide specific settings.

orcharhino applies host settings in the following order when nesting host groups:

  • Host settings take priority over host group settings.

  • Nested host group settings take priority over parent host group settings.

Example 1. Nested host group hierarchy

You create a top-level host group named Base and two nested host groups named Webserver and Storage. The nested host groups are associated with multiple hosts. You also create host custom.example.com that is not associated with any host group.

You define the operating system on the top-level host group (Base) and Ansible roles on the nested host groups (Webservers and Storage).

Top-level host group Nested host group Hosts Settings inherited from host groups

Base

This host group applies the Ubuntu 22.04.1 operating system setting.

Webservers

This host group applies the linux-system-roles.selinux Ansible role.

webserver1.example.com

Hosts use the following settings:

  • Ubuntu 22.04.1 defined by host group Base

  • linux-system-roles.selinux defined by host group Webservers

webserver2.example.com

Storage

This host group applies the linux-system-roles.postfix Ansible role.

storage1.example.com

Hosts use the following settings:

  • Ubuntu 22.04.1 defined by host group Base

  • linux-system-roles.postfix defined by host group Storage

storage2.example.com

[No host group]

custom.example.com

No settings inherited from host groups.

Example 2. Nested host group settings

You create a top-level host group named Base and two nested host groups named Webserver and Storage. You also create host custom.example.com that is associated with the top-level host group Base, but no nested host group.

You define different values for the operating system and Ansible role settings on the top-level host group (Base) and nested host groups (Webserver and Storage).

Top-level host group Nested host group Host Settings inherited from host groups

Base

This host group applies these settings:

  • The Ubuntu 22.04.1 operating system

  • The linux-system-roles.selinux Ansible role

Webservers

This host group applies these settings:

  • The Ubuntu 22.04.2 operating system

  • No Ansible role

webserver1.example.com

Hosts use the following settings:

  • The Ubuntu 22.04.2 operating system from host group Webservers

  • The linux-system-roles.selinux Ansible role from host group Base

webserver2.example.com

Storage

This host group applies these settings:

  • No operating system

  • The linux-system-roles.postfix Ansible role

storage1.example.com

Hosts use the following settings:

  • The Ubuntu 22.04.1 operating system from host group Base

  • The linux-system-roles.postfix Ansible role from host group Storage

storage2.example.com

[No nested host group]

custom.example.com

Host uses the following settings:

  • The Ubuntu 22.04.1 operating system from host group Base

  • The linux-system-roles.selinux Ansible role from host group Base

Creating a host group

Create a host group to be able to apply host settings to multiple hosts.

To use the CLI instead of the orcharhino management UI, see the CLI procedure.

Procedure
  1. In the orcharhino management UI, navigate to Configure > Host Groups and click Create Host Group.

  2. If you have an existing host group that you want to inherit attributes from, you can select a host group from the Parent list. If you do not, leave this field blank.

  3. Enter a Name for the new host group.

  4. Enter any further information that you want future hosts to inherit.

  5. Click the Ansible Roles tab, and from the Ansible Roles list, select one or more roles that you want to add to the host. Use the arrow icon to manage the roles that you add or remove.

  6. Click the additional tabs and add any details that you want to attribute to the host group.

    Puppet fails to retrieve the Puppet CA certificate while registering a host with a host group associated with a Puppet environment created inside a Production environment.

    To create a suitable Puppet environment to be associated with a host group, manually create a directory:

    # mkdir /etc/puppetlabs/code/environments/example_environment
  7. Click Submit to save the host group.

CLI procedure
  • Create the host group with the hammer hostgroup create command. For example:

    # hammer hostgroup create --name "Base" \
    --architecture "My_Architecture" \
    --content-source-id _My_Content_Source_ID_ \
    --content-view "_My_Content_View_" \
    --domain "_My_Domain_" \
    --lifecycle-environment "_My_Lifecycle_Environment_" \
    --locations "_My_Location_" \
    --medium-id _My_Installation_Medium_ID_ \
    --operatingsystem "_My_Operating_System_" \
    --organizations "_My_Organization_" \
    --partition-table "_My_Partition_Table_" \
    --puppet-ca-proxy-id _My_Puppet_CA_Proxy_ID_ \
    --puppet-environment "_My_Puppet_Environment_" \
    --puppet-proxy-id _My_Puppet_Proxy_ID_ \
    --root-pass "My_Password" \
    --subnet "_My_Subnet_"

Creating a host group for each lifecycle environment

Use this procedure to create a host group for the Library lifecycle environment and add nested host groups for other lifecycle environments.

Procedure

To create a host group for each lifecycle environment, run the following Bash script:

MAJOR="My_Major_OS_Version"
ARCH="My_Architecture"
ORG="My_Organization"
LOCATIONS="My_Location"
PTABLE_NAME="My_Partition_Table"
DOMAIN="My_Domain"

hammer --output csv --no-headers lifecycle-environment list --organization "${ORG}" | cut -d ',' -f 2 | while read LC_ENV; do
  [[ ${LC_ENV} == "Library" ]] && continue

  hammer hostgroup create --name "rhel-${MAJOR}server-${ARCH}-${LC_ENV}" \
    --architecture "${ARCH}" \
    --partition-table "${PTABLE_NAME}" \
    --domain "${DOMAIN}" \
    --organizations "${ORG}" \
    --query-organization "${ORG}" \
    --locations "${LOCATIONS}" \
    --lifecycle-environment "${LC_ENV}"
done

Adding a host to a host group

You can add a host to a host group in the orcharhino management UI.

Procedure
  1. In the orcharhino management UI, navigate to Hosts > All Hosts.

  2. Click the name of the host you want to modify.

  3. Click Edit.

  4. Select the host group from the Host Group list.

  5. Click Submit.

Verification
  • The Details card under the Overview tab now shows the host group your host belongs to.

Changing the host group of a host

Use this procedure to change the Host Group of a host.

If you reprovision a host after changing the host group, the fresh values that the host inherits from the host group will be applied.

Procedure
  1. In the orcharhino management UI, navigate to Hosts > All Hosts.

  2. Click the name of the host you want to modify.

  3. Click Edit.

  4. Select the new host group from the Host Group list.

  5. Click Submit.

Verification
  • The Details card under the Overview tab now shows the host group your host belongs to.

The text and illustrations on this page are licensed by ATIX AG under a Creative Commons Attribution Share Alike 4.0 International ("CC BY-SA 4.0") license. This page also contains text from the official Foreman documentation which uses the same license ("CC BY-SA 4.0").