Search code examples
salt-project

saltstack - how to get minions that match a grain or pillar?


Is there an easier way to get a list of minions that match a particular grain or pillar? Let's say I want to know all my Ubuntu 18.x hosts. Today I run:

$ sudo salt -G oscodename:bionic test.ping | awk -F: '/:/{print $1}' | sort 

I guess there's two questions (emphasis on the second q):

  • Does the master know ahead of time the grains/pillars of the minions or does it blast out the query to all the minions and let them decide if they match?
  • Is there a more efficient way of getting to that info?

Hopefully this is a really basic question. Any pointers to the documentation that covers this would be appreciated. My google-fu failed me on this one.


Solution

  • On the master:

    salt -G oscodename:bionic --preview-target
    

    The output is the list of minions matching that grain:

    - minion1
    - minion2
    

    Any parameter works which works for minion targeting, that includes pillars with -I or even both grains and pillars at the same time with -C.