0

I'm very new to Salt/Jinja/YAML so apologies if this is a silly question. I have a decent understanding of the high level stuff conceptually but I want to get in an start writing some States to get experience.

So I want to write a State that can compare the versions of the software installed on a server to versions defined elsewhere or hard-coded values, using Jinja. So even just really simple like:

if 'pythonVersion' > 2.7.5
    print a message

I've written bash scripts to get those software versions and run scripts using a Salt state, but how do I actually access server variables and work with them in the State itself?

  • 1
    This [question](https://stackoverflow.com/questions/45701907/how-to-compare-version-strings-in-salt-sls-files) covers the aspect of comparing versions in general, and the use of `pkg` module. This should help. – seshadri_c Jul 06 '23 at 11:12

1 Answers1

0

For example:

{% set pythonVersion = salt["pkg.version"]("python") %}
{% if salt["pkg.version_cmp"](pythonVersion, "2.7.5") > 0 %}
{% do salt["log.info"]("a message") %}
{% endif %}

But it depends what you mean by "server variables", "write a state", and "print a message". Depending on what your high-level problem is, you may not need to do any of those things in the first place.

OrangeDog
  • 36,653
  • 12
  • 122
  • 207