From 4b4280ccf482ba620bae4fa10f287a3ce7dbb368 Mon Sep 17 00:00:00 2001 From: Ruakij Date: Sat, 28 Nov 2026 12:42:53 +0000 Subject: [PATCH] common: kernel_modules loads kernel modules now and at boot, skipped in containers --- common/defaults/main.yml | 3 +++ common/tasks/kernel_modules.yml | 21 +++++++++++++++++++++ common/tasks/main.yml | 3 +++ 3 files changed, 27 insertions(+) create mode 100644 common/tasks/kernel_modules.yml diff --git a/common/defaults/main.yml b/common/defaults/main.yml index 6c4ce47..fd3424c 100755 --- a/common/defaults/main.yml +++ b/common/defaults/main.yml @@ -22,3 +22,6 @@ journald_size_cap: # Remove fail2ban from the host (only while the CrowdSec agent and bouncer run); set with # -e fail2ban_remove=true once CrowdSec covers the jails of the host. fail2ban_remove: false + +# Kernel modules loaded now and at boot (/etc/modules-load.d/ansible.conf). Skipped in containers. +kernel_modules: [] diff --git a/common/tasks/kernel_modules.yml b/common/tasks/kernel_modules.yml new file mode 100644 index 0000000..6719c38 --- /dev/null +++ b/common/tasks/kernel_modules.yml @@ -0,0 +1,21 @@ +# A container shares the kernel of its host, so the host loads the modules for it. +- block: + - name: Load kernel modules at boot + ansible.builtin.copy: + dest: /etc/modules-load.d/ansible.conf + content: "{{ kernel_modules | join('\n') }}\n" + mode: "0644" + when: kernel_modules | length > 0 + + - name: Remove the boot list of kernel modules + ansible.builtin.file: + path: /etc/modules-load.d/ansible.conf + state: absent + when: kernel_modules | length == 0 + + - name: Load kernel modules now + community.general.modprobe: + name: "{{ item }}" + state: present + loop: "{{ kernel_modules }}" + when: ansible_facts['virtualization_type'] not in ['lxc', 'docker', 'podman', 'container'] or ansible_facts['virtualization_role'] != 'guest' diff --git a/common/tasks/main.yml b/common/tasks/main.yml index 69fd5f3..4c2f8be 100755 --- a/common/tasks/main.yml +++ b/common/tasks/main.yml @@ -18,3 +18,6 @@ - import_tasks: ./journald.yml tags: journald + +- import_tasks: ./kernel_modules.yml + tags: kernel_modules