5

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?

OrangeDog
  • 36,653
  • 12
  • 122
  • 207
Geoff Crompton
  • 440
  • 1
  • 5
  • 15

1 Answers1

5

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 %}
ProT-0-TypE
  • 283
  • 2
  • 9
  • See [here](https://docs.saltproject.io/en/latest/ref/modules/all/salt.modules.aptpkg.html#salt.modules.aptpkg.version_cmp) for some documentation on the `version_cmp` function. Note that the exact module used varies (see [here](https://docs.saltproject.io/en/latest/ref/modules/all/salt.modules.pkg.html)) – Alex Dec 21 '21 at 09:20