Skip to main content

Ansible Search for kernel module loaded [Resolved]

I am trying to write an ansible playbook to check to see if a particular module is loaded for the current kernel running.

if I do an lsmod | grep my_module_$kernelVer

I would see something like

my_module_2_6_32_754_3_5_el6_x86_64

if I am on the 2.6.32-754.3.5.el6.x86_64 kernel

if I am still on that kernel and said module is

my_module_2_6_32_431_el6_x86_64

I need to rebuild the module for the current kernel that is on the server. I know how to do it in bash but I am not sure how to store a specific value with ansible and the register command and I am just learning ansible.

Thanks for any help provided.


Question Credit: flugo
Question Reference
Asked October 9, 2019
Posted Under: Unix Linux
10 views
1 Answers

if I do an lsmod | grep my_module_$kernelVer

Ok, that's the invocation of a shell module. It needs to be a shell because you're using |, and that's a shell construct.

I know how to do it in bash but I am not sure how to store a specific value with ansible and the register command and I am just learning ansible.

You can use the register to capture the results of the command and refer to it later. http://www.mydailytutorials.com/ansible-register-variables/ looks worth reading.

All that having been said, are you really sure you care so much about it matching? Okay, granted, the module not loading may be a big problem for you. But you're testing your kernel upgrades anyway, right? After all, the methodology you define here removes the loaded module to build a new one. I've loaded 3rd party modules in the past that don't even have a kernel version in the name, and frankly I prefer it. I'm not an expert on kernel modules, but keeping kernel versioning and module versions disassociated is worth considering.


credit: Daniel Farrell
Answered October 9, 2019
Your Answer