'How to save only the play recap of Ansible to a file?

The question is as the title said, how to save only the "play recap" of ansible to a file or variable?

I am trying to make a web UI using Flask to make the user use ansible easier without writing any script or playbook, just write some hosts' IP address and click on what you want to do and flask/python script will call and play the premade playbook. The problem is I can't really tell the user whether the task is successfully done or not, because it only shows on Linux terminal. Therefore I want to "catch" only the "play recap" of the playbook and show it on a web page to tell the user the result.



Solution 1:[1]

Since the environment and setup isn't further described, it is assumed you are just running ansible-playbook ... from CLI and send the output to STDOUT.

In such case you could use commands like

ansible-playbook deployment.yml | tee deployment.log
sed -n '/PLAY RECAP/,$p' deployment.log

and proceed further from there.

Thanks to

Regarding an own plugin, you may take advantage from Ansible Issue #14367 "Show aggregated playbook execution recap at the bottom of play recap" or Access Ansible playbook results after run.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 U880D