Chapter 3. 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. 3.1. 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. Important 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. Satellite 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 3.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 Red Hat Enterprise Linux 8.8 operating system setting. Webservers This host group applies the linux-system-roles.selinux Ansible role. webserver1.example.com Hosts use the following settings: Red Hat Enterprise Linux 8.8 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: Red Hat Enterprise Linux 8.8 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 3.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 Red Hat Enterprise Linux 8.8 operating system The linux-system-roles.selinux Ansible role Webservers This host group applies these settings: The Red Hat Enterprise Linux 8.9 operating system No Ansible role webserver1.example.com Hosts use the following settings: The Red Hat Enterprise Linux 8.9 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 Red Hat Enterprise Linux 8.8 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 Red Hat Enterprise Linux 8.8 operating system from host group Base The linux-system-roles.selinux Ansible role from host group Base 3.2. 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 Satellite web UI, see the CLI procedure . Procedure In the Satellite web UI, navigate to Configure > Host Groups and click Create Host Group . 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. Enter a Name for the new host group. Enter any further information that you want future hosts to inherit. 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. Click the additional tabs and add any details that you want to attribute to the host group. Note 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: Click Submit to save the host group. CLI procedure Create the host group with the hammer hostgroup create command. For example: 3.3. 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 "USD{ORG}" | cut -d ',' -f 2 | while read LC_ENV; do [[ USD{LC_ENV} == "Library" ]] && continue hammer hostgroup create --name "rhel-USD{MAJOR}server-USD{ARCH}-USD{LC_ENV}" \ --architecture "USD{ARCH}" \ --partition-table "USD{PTABLE_NAME}" \ --domain "USD{DOMAIN}" \ --organizations "USD{ORG}" \ --query-organization "USD{ORG}" \ --locations "USD{LOCATIONS}" \ --lifecycle-environment "USD{LC_ENV}" done 3.4. Adding a host to a host group You can add a host to a host group in the Satellite web UI. Procedure In the Satellite web UI, navigate to Hosts > All Hosts . Click the name of the host you want to modify. Click Edit . Select the host group from the Host Group list. Click Submit . Verification The Details card under the Overview tab now shows the host group your host belongs to. 3.5. 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 In the Satellite web UI, navigate to Hosts > All Hosts . Click the name of the host you want to modify. Click Edit . Select the new host group from the Host Group list. Click Submit . Verification The Details card under the Overview tab now shows the host group your host belongs to.

Commands:
mkdir /etc/puppetlabs/code/environments/ example_environment
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_"
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 "USD{ORG}" | cut -d ',' -f 2 | while read LC_ENV; do [[ USD{LC_ENV} == "Library" ]] && continue hammer hostgroup create --name "rhel-USD{MAJOR}server-USD{ARCH}-USD{LC_ENV}" --architecture "USD{ARCH}" --partition-table "USD{PTABLE_NAME}" --domain "USD{DOMAIN}" --organizations "USD{ORG}" --query-organization "USD{ORG}" --locations "USD{LOCATIONS}" --lifecycle-environment "USD{LC_ENV}" done