Este conteúdo não está disponível no idioma selecionado.
Chapter 6. Configuring kernel parameters permanently by using the kernel_settings RHEL System Role
As an experienced user with good knowledge of Red Hat Ansible, you can use the kernel_settings role to configure kernel parameters on multiple clients at once. This solution:
- Provides a friendly interface with efficient input setting.
- Keeps all intended kernel parameters in one place.
After you run the kernel_settings role from the control machine, the kernel parameters are applied to the managed systems immediately and persist across reboots.
Note that RHEL System Role delivered over RHEL channels are available to RHEL customers as an RPM package in the default AppStream repository. RHEL System Role are also available as a collection to customers with Ansible subscriptions over Ansible Automation Hub.
6.1. Introduction to the kernel_settings role Copiar o linkLink copiado para a área de transferência!
RHEL System Roles is a set of roles that provide a consistent configuration interface to remotely manage multiple systems.
RHEL System Roles were introduced for automated configurations of the kernel using the kernel_settings System Role. The rhel-system-roles package contains this system role, and also the reference documentation.
To apply the kernel parameters on one or more systems in an automated fashion, use the kernel_settings role with one or more of its role variables of your choice in a playbook. A playbook is a list of one or more plays that are human-readable, and are written in the YAML format.
You can use an inventory file to define a set of systems that you want Ansible to configure according to the playbook.
With the kernel_settings role you can configure:
-
The kernel parameters using the
kernel_settings_sysctlrole variable -
Various kernel subsystems, hardware devices, and device drivers using the
kernel_settings_sysfsrole variable -
The CPU affinity for the
systemdservice manager and processes it forks using thekernel_settings_systemd_cpu_affinityrole variable -
The kernel memory subsystem transparent hugepages using the
kernel_settings_transparent_hugepagesandkernel_settings_transparent_hugepages_defragrole variables
6.2. Applying selected kernel parameters using the kernel_settings role Copiar o linkLink copiado para a área de transferência!
Follow these steps to prepare and apply an Ansible playbook to remotely configure kernel parameters with persisting effect on multiple managed operating systems.
Prerequisites
-
You have
rootpermissions. -
Entitled by your RHEL subscription, you installed the
ansible-coreandrhel-system-rolespackages on the control machine. - An inventory of managed hosts is present on the control machine and Ansible is able to connect to them.
Procedure
Optionally, review the
inventoryfile for illustration purposes:Copy to Clipboard Copied! Toggle word wrap Toggle overflow The file defines the
[testingservers]group and other groups. It allows you to run Ansible more effectively against a specific set of systems.Create a configuration file to set defaults and privilege escalation for Ansible operations.
Create a new YAML file and open it in a text editor, for example:
vi /home/jdoe/<ansible_project_name>/ansible.cfg
# vi /home/jdoe/<ansible_project_name>/ansible.cfgCopy to Clipboard Copied! Toggle word wrap Toggle overflow Insert the following content into the file:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow The
[defaults]section specifies a path to the inventory file of managed hosts. The[privilege_escalation]section defines that user privileges be shifted torooton the specified managed hosts. This is necessary for successful configuration of kernel parameters. When Ansible playbook is run, you will be prompted for user password. The user automatically switches torootby means ofsudoafter connecting to a managed host.
Create an Ansible playbook that uses the
kernel_settingsrole.Create a new YAML file and open it in a text editor, for example:
vi /home/jdoe/<ansible_project_name>/kernel-roles.yml
# vi /home/jdoe/<ansible_project_name>/kernel-roles.ymlCopy to Clipboard Copied! Toggle word wrap Toggle overflow This file represents a playbook and usually contains an ordered list of tasks, also called plays, that are run against specific managed hosts selected from your
inventoryfile.Insert the following content into the file:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow The
namekey is optional. It associates an arbitrary string with the play as a label and identifies what the play is for. Thehostskey in the play specifies the hosts against which the play is run. The value or values for this key can be provided as individual names of managed hosts or as groups of hosts as defined in theinventoryfile.The
varssection represents a list of variables containing selected kernel parameter names and values to which they have to be set.The
roleskey specifies what system role is going to configure the parameters and values mentioned in thevarssection.NoteYou can modify the kernel parameters and their values in the playbook to fit your needs.
Optionally, verify that the syntax in your play is correct.
ansible-playbook --syntax-check kernel-roles.yml
# ansible-playbook --syntax-check kernel-roles.yml playbook: kernel-roles.ymlCopy to Clipboard Copied! Toggle word wrap Toggle overflow This example shows the successful verification of a playbook.
Execute your playbook.
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Before Ansible runs your playbook, you are going to be prompted for your password and so that a user on managed hosts can be switched to
root, which is necessary for configuring kernel parameters.The recap section shows that the play finished successfully (
failed=0) for all managed hosts, and that 4 kernel parameters have been applied (changed=4).- Restart your managed hosts and check the affected kernel parameters to verify that the changes have been applied and persist across reboots.