Chapter 16. Configuring kernel parameters permanently by using RHEL system roles You can use the kernel_settings RHEL system role to configure kernel parameters on multiple clients simultaneously. Simultaneous configuration has the following advantages: 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. Important 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. 16.1. Applying selected kernel parameters by using the kernel_settings RHEL system role You can use the kernel_settings RHEL system role to remotely configure various kernel parameters across multiple managed operating systems with persistent effects. For example, you can configure: Transparent hugepages to increase performance by reducing the overhead of managing smaller pages. The largest packet sizes to be transmitted over the network with the loopback interface. Limits on files to be opened simultaneously. Prerequisites You have prepared the control node and the managed nodes . You are logged in to the control node as a user who can run playbooks on the managed nodes. The account you use to connect to the managed nodes has sudo permissions on them. Procedure Create a playbook file, for example ~/playbook.yml , with the following content: --- - name: Configuring kernel settings hosts: managed-node-01.example.com tasks: - name: Configure hugepages, packet size for loopback device, and limits on simultaneously open files. ansible.builtin.include_role: name: rhel-system-roles.kernel_settings vars: kernel_settings_sysctl: - name: fs.file-max value: 400000 - name: kernel.threads-max value: 65536 kernel_settings_sysfs: - name: /sys/class/net/lo/mtu value: 65000 kernel_settings_transparent_hugepages: madvise kernel_settings_reboot_ok: true The settings specified in the example playbook include the following: kernel_settings_sysfs: <list_of_sysctl_settings> A YAML list of sysctl settings and the values you want to assign to these settings. kernel_settings_transparent_hugepages: <value> Controls the memory subsystem Transparent Huge Pages (THP) setting. You can disable THP support ( never ), enable it system wide ( always ) or inside MAD_HUGEPAGE regions ( madvise ). kernel_settings_reboot_ok: <true|false> The default is false . If set to true , the system role will determine if a reboot of the managed host is necessary for the requested changes to take effect and reboot it. If set to false , the role will return the variable kernel_settings_reboot_required with a value of true , indicating that a reboot is required. In this case, a user must reboot the managed node manually. For details about all variables used in the playbook, see the /usr/share/ansible/roles/rhel-system-roles.kdump/README.md file on the control node. Validate the playbook syntax: Note that this command only validates the syntax and does not protect against a wrong but valid configuration. Run the playbook: Verification Verify the affected kernel parameters: Additional resources /usr/share/ansible/roles/rhel-system-roles.kernel_settings/README.md file /usr/share/doc/rhel-system-roles/kernel_settings/ directory

Commands:
--- - name: Configuring kernel settings hosts: managed-node-01.example.com tasks: - name: Configure hugepages, packet size for loopback device, and limits on simultaneously open files. ansible.builtin.include_role: name: rhel-system-roles.kernel_settings vars: kernel_settings_sysctl: - name: fs.file-max value: 400000 - name: kernel.threads-max value: 65536 kernel_settings_sysfs: - name: /sys/class/net/lo/mtu value: 65000 kernel_settings_transparent_hugepages: madvise kernel_settings_reboot_ok: true
ansible-playbook --syntax-check ~/playbook.yml
ansible-playbook ~/playbook.yml
ansible managed-node-01.example.com -m command -a 'sysctl fs.file-max kernel.threads-max net.ipv6.conf.lo.mtu' ansible managed-node-01.example.com -m command -a 'cat /sys/kernel/mm/transparent_hugepage/enabled'