How to Configure Kernel Parameters in RedHat-like Linux systems with Ansible using system role?
I'm going to show you a live Playbook with some simple Ansible code.
I'm Luca Berton and welcome to today's episode of Ansible Pilot.
Ansible Configure Kernel Parameters in RedHat-like systems
linux-system-rolesFedora, Enterprise Linux & CentOS
rhel-system-rolespackage Red Hat Enterprise Linux
Today we're talking about linux-system-role.
This is a swiss army that you need to absolutely add to your IT knowledge.
Currently, there are 21 roles to configure a lot of system properties.
The roles are developed and tested for RedHat-like systems but the project might expand in the future.
It's available as a package named linux-system-role for Fedora, Enterprise Linux, and CentOS.
In Red Hat Enterprise Linux is named rhel-system-roles and is available since RHEL 8.
If you would like to know more about the available roles and jump immediately to the Ansible Galaxy page or the official website.
Links
- https://galaxy.ansible.com/linux-system-roles
- https://linux-system-roles.github.io/
## Playbook
Configure Kernel Parameters in RedHat-like Linux systems with Ansible System Role
code
``yaml
---
- name: kernel_settings Playbook
hosts: all
become: true
vars:
kernel_settings_sysctrl:
- 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
roles:
- linux-system-roles.kernel_settings
`
execution
``bash
$ ansible-playbook -i inventory kernel_settings.yml
PLAY [kernel_settings Playbook] *
TASK [Gathering Facts]
[DEPRECATION WARNING]: Distribution fedora 35 on host fedora.example.com should use
/usr/bin/python3, but is using /usr/bin/python for backward compatibility with prior Ansible
releases. A future Ansible release will default to using the discovered platform python for this
host. See https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html for
more information. This feature will be removed in version 2.12. Deprecation warnings can be
disabled by setting deprecation_warnings=False in ansible.cfg.
ok: [fedora.example.com]
TASK [linux-system-roles.kernel_settings : Set version specific variables] **
ok: [fedora.example.com]
TASK [linux-system-roles.kernel_settings : Ensure required packages are installed]
ok: [fedora.example.com]
TASK [linux-system-roles.kernel_settings : Ensure required services are enabled and started]
ok: [fedora.example.com] => (item=tuned)
TASK [linux-system-roles.kernel_settings : Ensure kernel settings profile directory exists] *
ok: [fedora.example.com]
TASK [linux-system-roles