Does saltstack have an equivalent to puppets versioncmp() function? Or alternatively, is there a way to get the distutils.version or packaging.version.parse methods (as mentioned on Compare version strings in Python) available in a jinja+yaml rendered sls file?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
you can use the module pkg.version_cmp
:
# salt-call pkg.version_cmp '1.0.2' '1.1.1'
local:
-1
# salt-call pkg.version_cmp '0.2.4.1-0ubuntu1' '0.2.4-0ubuntu1'
local:
1
Inside jinja you can use it in a way similar to:
{% if salt['pkg.version_cmp']('1.1.0','1.0.5') > 0 %}
....
{% endif %}