# Get output from ansible.playbook.PlayBook()

**URL:** <https://forum.ansible.com/t/get-output-from-ansible-playbook-playbook/16973>\
**Category:** Ansible Project\
**Created:** [December 5, 2014, 5:16pm UTC](https://forum.ansible.com/t/get-output-from-ansible-playbook-playbook/16973 "2014-12-05T17:16:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Romey-Rome](https://avatars.discourse-cdn.com/v4/letter/r/4da419/32.png) [@Romey-Rome](https://forum.ansible.com/u/Romey-Rome)\
**Post date:** [December 5, 2014, 5:16pm UTC](https://forum.ansible.com/t/get-output-from-ansible-playbook-playbook/16973/1 "2014-12-05T17:16:27Z")

</div>

I’m executing a playbook from a Flask web service. All output goes to stdout console. I need it in my webapp so that I can send it back to the browser. Best I can get on the server is the summary stats counter from the pb object. (success,skipped,failed,etc)

How can I get the complete output like with ansible.Runner()?

stats = callbacks.AggregateStats()  
playbook\_cb = callbacks.PlaybookCallbacks(verbose=utils.VERBOSITY)  
runner\_cb = callbacks.PlaybookRunnerCallbacks(stats,verbose=utils.VERBOSITY)

pb = ansible.playbook.PlayBook(  
playbook = playbook  
stats=stats,  
inventory=targets,  
callbacks=playbook\_cb,  
runner\_callbacks=runner\_cb  
).run()

Thanks!

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [December 8, 2014, 5:30pm UTC](https://forum.ansible.com/t/get-output-from-ansible-playbook-playbook/16973/2 "2014-12-08T17:30:09Z")

</div>

Moving this to ansible-devel.

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [December 8, 2014, 5:34pm UTC](https://forum.ansible.com/t/get-output-from-ansible-playbook-playbook/16973/3 "2014-12-08T17:34:49Z")

</div>

You could always capture stdout and stderr via something like:

import sys  
from cStringIO import StringIO

sys\_stdout = sys.stdout  
sys\_stderr = sys.stderr

sys.stdout = StringIO()  
sys.stderr = StringIO()

# run ansible.playbook.Playbook here

stdout = sys.stdout.getvalue()  
stderr = sys.stderr.getvalue()

sys.stdout = sys\_stdout  
sys.stderr = sys\_stderr

There are a number of different ways to go about this. Including, creating your own callback class and registering that instead.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [December 9, 2014, 1:08pm UTC](https://forum.ansible.com/t/get-output-from-ansible-playbook-playbook/16973/4 "2014-12-09T13:08:35Z")

</div>

Ansible uses callback plugins for everything, so basically you’re going to need to write one.

I recommend Ansible Tower for easier API access for integrating with web applications - not only is the REST API very well designed for this, you avoid possible licensing issues if redistributing your app, can build your apps in any language (not just Python), don’t have to deal with resource scheduling (already there), and also don’t have to deal with a possibly changing callback internals.
