Search code examples
salt-project

Saltstack: How to define in top.sls "Package less than version ..."


I have the following issue:

I use salt stack to manage my minions, which are running in different datacenters. But the package repositories are not consistent: Not all have the latest versions of salt. With Salt stack I can of course work around that, so I added to the top.sls:

'not G@saltversion:3003.1':  
  - fixes.saltversion

But I don't like that up there. I've tried several variants, but couldn't manage to select minions which have a specific grain less than a specific version. Like in this case: To select all minions which have an older version than 3003.1 to apply a state on them, that gets the package directly from a different repo.

How do I select "less than" of a Grain?

I've googled around already and didn't find anything matching my case. The Docs are also not helpful for my case. I've read about custom matcher: But do I really need to implement a custom matcher for that?

Thanks in advance for your help everyone


Solution

  • Have a look at the following grain: saltversioninfo. This grain is a list: [ majorversion, patchversion ].

    You can target minions with releases later than Fluorine (2019.2.0) like this:

    'P@saltversioninfo:0:\b(?:3[0-9]{2}[0-2])\b or ( G@saltversioninfo:0:3003 and G@saltversioninfo:1:0 ):
      - match: compound
      - fixes.saltversion
    

    This compound match will target minions with release between 3000 and 3003.0.

    This is a bit static and you need to modify this after a new release. But I hope this will help you.

    EDIT:

    The matcher above is untested, I don't have minions with older version. You should test the matcher before with the following salt command:

    salt -C 'P@saltversioninfo:0:\b(?:3[0-9]{2}[0-2])\b or ( G@saltversioninfo:0:3003 and G@saltversioninfo:1:0 )' test.ping