1

After reading this and working on what I found there: How to compare kernel (or other) version numbers in Ansible I ran into a problem.

What if the kernel version is something like: 4.15.0-173-generic ?

If I do something like this:

    - name: Compare kernel version
      set_fact:
        checks_out: "{{ ansible_kernel is version('4.15.0-173.456', '>=') }}"

This gives an error:

FAILED! => {"msg": "Version comparison: '<' not supported between instances of 'str' and 'int'"}

When checking for specific kernel versions, for instance for the purpose of investigating if an host is vulnerable to a CVE, this is hindering.

If I remove the .456 it works, but I feel like this is going to be a situation where the generic kernel still needs to be updated and rebooted.

How I do get I around this?

KdgDev
  • 14,299
  • 46
  • 120
  • 156

1 Answers1

3
    - name: Compare kernel version
      set_fact:
        checks_out: "{{ ansible_facts.kernel | replace('-generic', '') is version('4.15.0-173.456', '>=') }}"
flowerysong
  • 2,921
  • 4
  • 13