ansibleansible-2.xversion-numbering

How to compare kernel, software, etc. versions numbers in Ansible?


For a role I'm developing I need to verify that the kernel version is greater than a particular version.

I've found the ansible_kernel fact, but is there an easy way to compare this to other versions? I thought I might manually explode the version string on the dots (.) and compare the numbers, but I can't even find a friendly filter to explode the version string out, so I'm at a loss.


Solution

  • There is a version test for it:

    {{ ansible_distribution_version is version('12.04', '>=') }}
        
    {{ sample_version_var is version('1.0', operator='lt', strict=True) }}
    

    Prior to Ansible 2.5, all tests were also provided as filters, so, the same was achievable with a filter, named version_compare, but in current versions of Ansible, the test was renamed and, overall, the tests and filters have been clearly disambiguated

    {{ ansible_distribution_version | version_compare('12.04', '>=') }}    
        
    {{ sample_version_var | version_compare('1.0', operator='lt', strict=True) }}