Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to compare kernel (or other) version 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 .'s 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.

like image 257
TobyG Avatar asked Sep 29 '16 20:09

TobyG


People also ask

How do I compare versions in Ansible?

For example, you may need to check the current version of an application and compare it with the latest one to take a decision if update is required. To compare versions in Ansible we can use the version test, and in this note i will show the examples of how to use it.

What is Ansible fact?

Ansible facts are data gathered about target nodes (host nodes to be configured) and returned back to controller nodes. Ansible facts are stored in JSON format and are used to make important decisions about tasks based on their statistics. Facts are in an ansible_facts variable, which is managed by Ansible Engine.


1 Answers

There is a test for it:

{{ ansible_distribution_version is version('12.04', '>=') }}  {{ sample_version_var is version('1.0', operator='lt', strict=True) }} 
like image 100
Konstantin Suvorov Avatar answered Sep 25 '22 03:09

Konstantin Suvorov