Compare version numbers using jinja2

孤者浪人 提交于 2019-12-23 12:01:29

问题


I am using jinja2 template to install/upgrade packages.

The logic was setting a variable for current installed version and compare it with the available version. It was working fine but once we passed in to 10.x, comparison quit working.

Is it possible to cast the variable so it can correctly identify 10.9.8 is greater than 9.8.7?

Thanks

current_version=['9.8.7']

{% if current_version < '10.9.8' %}


回答1:


There's a special test version_compare:

{% if current_version | version_compare('10.9.8', '<') %}

current_version should be string (it is a list in your example).




回答2:


In saltstack you can use pkg.version_cmp

See my reply here: How to compare version strings in salt sls files



来源:https://stackoverflow.com/questions/46324330/compare-version-numbers-using-jinja2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!