Salt: [outputter] add sort option

Created on 19 Mar 2015  路  9Comments  路  Source: saltstack/salt

We have minions named by this scheme:


So I would like to get results sorted by minions id, but not by their response time.

Instead of this:

$ salt -v '*tula*' pkg.version WeightControlSystem
Executing job with jid 20150319105503810996
-------------------------------------------

stolb-db.tula_3:
    3.0.1.26-20150318T1336
stolb-db.tula_4:
    3.0.1.26-20150318T1336
stolb-db.tula_2:
    Minion did not return. [Not connected]
stolb-db.tula_1:
    Minion did not return. [Not connected]

I want to get this:

$ salt -v '*tula*' pkg.version WeightControlSystem
Executing job with jid 20150319105503810996
-------------------------------------------

stolb-db.tula_1:
    Minion did not return. [Not connected]
stolb-db.tula_2:
    Minion did not return. [Not connected]
stolb-db.tula_3:
    3.0.1.26-20150318T1336
stolb-db.tula_4:
    3.0.1.26-20150318T1336

Unfortunately there is not simple way to sort YAML with the help of *NIX utilities.

Core Feature P3 stale

Most helpful comment

I usually fix this by outputting as txt and sorting.

$ salt --out txt '*' grains.item saltversion  | sort
minion1: {'saltversion': '2016.3.2'}
minion2: {'saltversion': '2016.3.2'}

The pipe will wait until all minions have returned (or timed out), in case you didn't know... :-)

All 9 comments

It's not possible to sort minion returns currently because their results are printed in the order they return. Often users who have many minions will not even interact with minion data on the command line because it doesn't scale and instead have custom returners streaming return data into databases or some other visualizing tool. I'm sure I remember @basepi saying that this feature has been requested more than once before. You could create a custom outputter that batches minion returns and then prints after they all return or after you reach a certain timeout or either.

Not only are they printed in the order they return, they're printed _as they return_, which makes it even harder to sort them, we would have to batch like you mentioned. Outputters that operate on all the returned data after it is all returned are something we want to add. There's an open issue somewhere though I don't have it off the top of my head.

It would be great to have this (and other) output methods that work on the returned data in toto.

On this topic, but with a slightly different approach... Is there an easy way to get salt to prepend each line with the minion name, so I can just pipe the output of salt to sort ? Currently, i do something like "salt something* test.ping | sort | uniq" to see a list of the machines I am picking to make sure my glob (or grain match or whatever) does what I think. Then I "salt something* somestate.doawesome" and hope for the best. If I could usefully sort the output of salt and get it to sort all the output by machine, it would be easier to skim and make sure it did what I expect.

Was this feature ever added?

I am not aware that it has, no.

I usually fix this by outputting as txt and sorting.

$ salt --out txt '*' grains.item saltversion  | sort
minion1: {'saltversion': '2016.3.2'}
minion2: {'saltversion': '2016.3.2'}

The pipe will wait until all minions have returned (or timed out), in case you didn't know... :-)

If you want to sort numerically rather than alphabetically use sort --version-sort

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

If this issue is closed prematurely, please leave a comment and we will gladly reopen the issue.

Was this page helpful?
0 / 5 - 0 ratings