How to sort ansible output

1,055 views
Skip to first unread message

The Wanderer

unread,
Apr 12, 2018, 3:42:16 PM4/12/18
to Ansible Project
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?

Biswadip Dutta

unread,
Apr 13, 2018, 2:19:52 AM4/13/18
to ansible...@googlegroups.com
I'd suggest you do the sorting part later. I mean after you get the Ansible results and then sort it.

Regards,
Biswadip Dutta

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/2090253c-01a4-4db7-abe4-6275615ad826%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

The Wanderer

unread,
Apr 13, 2018, 3:00:24 AM4/13/18
to ansible...@googlegroups.com
I know, but how?

--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/i5uql5fjrAg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-project+unsubscribe@googlegroups.com.

To post to this group, send email to ansible-project@googlegroups.com.

Biswadip Dutta

unread,
Apr 13, 2018, 4:53:21 AM4/13/18
to ansible...@googlegroups.com
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. 

Regards,
Biswadip Dutta

Brian Coca

unread,
Apr 13, 2018, 10:49:53 PM4/13/18
to Ansible Project
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.




--
----------
Brian Coca
Reply all
Reply to author
Forward
0 new messages