Leverage community.general.modprobe for kernel module management

At the moment for deb systems we use `/etc/modules` file which
is symlinked to `/etc/modules-load.d/modules.conf` file by default.

With that for EL we using
`/etc/modules-load.d/openstack-ansible.conf` which is better place
in general, but also does not prevent risk of direct conflicts with
default system configration.

Usage of `persistent` key of community.general.modprobe (which was
added in 7.0.0) allows us to not only load the module in runtime, but
also define/remove module from being loaded on boot based on the
condition.

With that we also add `params` key, which allows to supply custom
module configuration and is also controlled by `persistent` key.

Depends-On: https://review.opendev.org/c/openstack/openstack-ansible-plugins/+/951869
Change-Id: I0e910387e021136a0680f0e6d1c63fc29ed0c6ff
Signed-off-by: Dmitriy Rabotyagov <dmitriy.rabotyagov@cleura.com>
This commit is contained in:
Dmitriy Rabotyagov
2025-06-05 14:51:18 +02:00
parent 05853abc3e
commit 59890b5ceb
8 changed files with 36 additions and 15 deletions

View File

@@ -52,6 +52,9 @@ openstack_host_specific_kernel_modules: []
# openstack_host_specific_kernel_modules:
# - name: "ebtables"
# pattern: "CONFIG_BRIDGE_NF_EBTABLES"
# - name: vfio-pci
# condition: "{{ nova_device_spec is defined and nova_device_spec | length > 0 }}"
# params: "ids={% for spec in nova_device_spec | default([]) %}{{ spec.vendor_id }}:{{ spec.product_id }}{% if not loop.last %},{% endif %}{% endfor %}"
## Where:
## :param name: name of the kernel module
## :param pattern: pattern to grep for in /boot/config-$kernel_version to check how module is configured inside kernel

View File

@@ -0,0 +1,12 @@
---
features:
- |
Added key ``params`` to the variable ``openstack_host_specific_kernel_modules``
which allows to supply module parameters as a simple string.
upgrade:
- |
Kernel modules loaded by OpenStack-Ansible will be defined for load in their own
files under ``/etc/modules-load.d/``. Prior paths managed by OpenStack-Ansible
like ``/etc/modules-load.d/openstack-ansible.conf`` for EL systems or
``/etc/modules`` for DEB systems will be cleaned out from managed modules during
upgrade.

View File

@@ -58,19 +58,34 @@
- (modules.content | b64decode).find(item.pattern + ' is not set') != -1
- name: "Load kernel module(s)"
vars:
_kernel_module_state: "{{ (item.condition | default(true)) | ternary('present', 'absent') }}"
community.general.modprobe:
name: "{{ item.name }}"
state: "{{ _kernel_module_state }}"
persistent: "{{ _kernel_module_state }}"
params: "{{ item.params | default(omit) }}"
with_items: "{{ openstack_host_kernel_modules + openstack_host_specific_kernel_modules }}"
when:
- item.name | length > 0
- item.pattern is undefined or (item.pattern is defined and (modules.content | b64decode).find(item.pattern + '=m') != -1)
- item.condition | default(true)
- name: Write list of modules to load at boot
ansible.builtin.template:
src: modprobe.conf.j2
dest: "{{ openstack_host_module_file }}"
mode: "0644"
# TODO: Remove after 2026.1 release
- name: Clean-up ex-default modules location
ansible.builtin.lineinfile:
path: /etc/modules
line: "{{ item.name }}"
state: absent
loop: "{{ openstack_host_kernel_modules + openstack_host_specific_kernel_modules }}"
when:
- ansible_facts['os_family'] | lower == 'debian'
- item.name | length > 0
# TODO: Remove after 2026.1 release
- name: Remove ex-default modules location
ansible.builtin.file:
path: /etc/modules-load.d/openstack-ansible.conf
state: absent
- name: Adding new system tuning
ansible.posix.sysctl:

View File

@@ -1,5 +0,0 @@
# {{ ansible_managed }}
# Modules from the openstack-ansible-openstack_hosts role
{% for module in openstack_host_kernel_modules + openstack_host_specific_kernel_modules %}
{{ module.name }}
{% endfor %}

View File

@@ -18,7 +18,6 @@ openstack_host_required_kernel: 4.9.0-0-amd64
openstack_host_sysstat_file: /etc/default/sysstat
openstack_host_sysstat_cron_file: /etc/cron.d/sysstat
openstack_host_cron_template: sysstat.cron.debian.j2
openstack_host_module_file: /etc/modules
## Kernel modules loaded on hosts
openstack_host_kernel_modules:

View File

@@ -18,7 +18,6 @@ openstack_host_required_kernel: 6.12.0
openstack_host_sysstat_file: /etc/sysconfig/sysstat
openstack_host_sysstat_cron_file: /etc/cron.d/sysstat
openstack_host_cron_template: sysstat.cron.redhat.j2
openstack_host_module_file: /etc/modules-load.d/openstack-ansible.conf
openstack_host_sysstat_cron_mode: "0600"

View File

@@ -18,7 +18,6 @@ openstack_host_required_kernel: 4.18.0
openstack_host_sysstat_file: /etc/sysconfig/sysstat
openstack_host_sysstat_cron_file: /etc/cron.d/sysstat
openstack_host_cron_template: sysstat.cron.redhat.j2
openstack_host_module_file: /etc/modules-load.d/openstack-ansible.conf
openstack_host_sysstat_cron_mode: "0600"

View File

@@ -18,7 +18,6 @@ openstack_host_required_kernel: 5.4.0-0-generic
openstack_host_sysstat_file: /etc/default/sysstat
openstack_host_sysstat_cron_file: /etc/cron.d/sysstat
openstack_host_cron_template: sysstat.cron.debian.j2
openstack_host_module_file: /etc/modules
## Kernel modules loaded on hosts
openstack_host_kernel_modules: