Loading...

Watch: Load and Unload Kernel Modules in Linux - Ansible module modprobe

How to automate the Linux Kernel module loading of the "dummy" module with parameters on an example machine with Ansible.

How to Load and Unload Kernel Modules in Linux with Ansible?

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 Load and Unload Kernel Modules in Linux

  • community.general.modprobe
  • Load or unload kernel modules

Today we're talking about the Ansible module modprobe.

The full name is community.general.modprobe, which means that is part of the collection of modules "community.general" maintained by the Ansible Community.

The purpose of the module is to Load or unload kernel modules.

Parameters

  • name string - Name of kernel module
  • params string - Modules parameters
  • state string - present/absent - Load / Unload

The parameters of the module modprobe.

The only required parameter is "name", with the full Linux kernel module name.

The parameter "params" allows you to specify some module parameters. Default is an empty string.

The parameter "state" specifies the status of the Linux Kernel module. The option "present" means that the module must be loaded. The option "absent" means that the module must be unloaded.

Links

  • https://docs.ansible.com/ansible/latest/collections/community/general/modprobe_module.html

## Playbook

Load and Unload Kernel Modules in Linux with Ansible Playbook.

code

``yaml

---

  • name: modprobe module Playbook

hosts: all

become: true

vars:

module_name: "dummy"

module_params: "numdummies=2"

tasks:

- name: load the module

community.general.modprobe:

name: "{{ module_name }}"

state: present

params: "{{ module_params }}"

`

execution

``bash

$ ansible-playbook -i virtualmachines/demo/inventory modprobe/modprobe.yml

PLAY [modprobe module Playbook] *

TASK [Gathering Facts]

ok: [demo.example.com]

TASK [Add the dummy module] *

changed: [demo.example.com]

PLAY RECAP **

demo.example.com : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0

idempotency

$ ansible-playbook -i virtualmachines/demo/inventory modprobe/modprobe.yml

PLAY [modprobe module Playbook] *

Read the full tutorial: Load and Unload Kernel Modules in Linux - Ansible module modprobe