I want to use Ansible to collect information from a number of servers. The information should be postprocessed locally, so it should be presented in a certain format. Other than grep
and sed
and awk
and other sysadmin's best friends, how do I get from Ansible what is relevant to the task and nothing else?
There must be a way either to run Ansible from Python, exporting variables to the wrapping script, or to run Python from Ansible to customize the output.
Ansible is indeed directly callable from your own python script. The Ansible API is fully documented. I have not used it myself but you should be able to write your own python script to leverage Ansible and do what you want. According to their documentation is as simple as this:
There's a more thorough example in the documentation that I linked to.