Bootstrap FreeKB - Ansible - Get Kernel version using the ansible_kernel fact
Ansible - Get Kernel version using the ansible_kernel fact

Updated:   |  Ansible articles

The ansible_kernel fact can be used to get the Kernel being used by the target system. Take for example the following playbook. Do not set gather_facts: false since ansible_kernel is a gathered fact.

---
- hosts: localhost
  tasks:
  - debug:
      var: ansible_kernel
...

 

Which should return something like this.

ok: [localhost] => {
    "ansible_kernel": "5.14.0-284.30.1.el9_2.x86_64"
}

 

This should be the same as the uname --kernel-release command output.

~}# uname --kernel-release
5.14.0-284.30.1.el9_2.x86_64

 

Likewise, on a Red Hat distribution (CentOS, Fedora, Red Hat), this should be similar to the kernel listed in the dnf list or yum list command output.

~]# yum list installed kernel
Installed Packages
kernel.x86_64                      4.18.0-477.21.1.el8_8       @rhel-8-for-x86_64-baseos-rpms 
kernel.x86_64                      4.18.0-477.27.1.el8_8       @rhel-8-for-x86_64-baseos-rpms
kernel.x86_64                      5.14.0-284.30.1.el9_2       @System

 

And for systems that contain the grubby CLI, this should be similar to the kernel returned by the grubby --default-kernel and grubby --default-title output.

~]# grubby --default-kernel
/boot/vmlinuz-5.14.0-284.30.1.el9_2.x86_64

~]# grubby --default-title
Red Hat Enterprise Linux (5.14.0-284.30.1.el9_2.x86_64) 9.2 (Plow)

 

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 4e08f7 in the box below so that we can be sure you are a human.