How to sort ansible output

Hi all,

I have a couple of servers that are managed via ansible. On all of them, I have got a script - free.sh - that when run, outputs just the free memory, like - 5GB. This is not the free system RAM, but a value that’s obtained by complex calculations done via the script. I can call the script via ansible in this manner:

ansible -bK -a “/usr/bin/free.sh” apache-servers

(where apache-servers is the host-group on which I want to run the script)

And here’s the limitation that I’m facing - Ansible just returns results in the order the job completes. But, I want the result to be sorted according to the script’s output. Is this possible?

I’d suggest you do the sorting part later. I mean after you get the Ansible results and then sort it.

I know, but how?

Oh okay. I think I misunderstood your query. What I was suggesting is that you can write another script to sort the output based on your needs.
I don’t think Ansible has such functionality. If there’s one then I will also like to know.

ansible -m script -a 'free.sh' |sort?

you can also use --tree to save a file with the output of each server

or you can just write your own callback to handle the output.