# Ansible API

**URL:** <https://forum.ansible.com/t/ansible-api/12702>\
**Category:** Ansible Project\
**Created:** [April 19, 2013, 8:11pm UTC](https://forum.ansible.com/t/ansible-api/12702 "2013-04-19T20:11:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Antonio\_Messina](https://avatars.discourse-cdn.com/v4/letter/a/9de053/32.png) [@Antonio\_Messina](https://forum.ansible.com/u/Antonio_Messina)\
**Post date:** [April 19, 2013, 8:11pm UTC](https://forum.ansible.com/t/ansible-api/12702/1 "2013-04-19T20:11:30Z")

</div>

Hi all,

As I mentioned in a previous email, we are using ansible from a python  
program to creates and configure HPC clusters on a cloud using, of  
course, ansible.

The reason why I am writing is because we would like to filter the  
output from ansible, and displaying it only if a reasonable amount of  
`-v` options are given. However, we couldn't find an easy way to do  
it.

This is the code we are using:

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;stats = callbacks.AggregateStats()  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;playbook\_cb = callbacks.PlaybookCallbacks(verbose=0)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;runner\_cb = callbacks.PlaybookRunnerCallbacks(stats, verbose=0)

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pb = PlayBook(  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;playbook=self.\_playbook\_path,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;host\_list=inventory\_path,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;remote\_user=self.\_remote\_user,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;callbacks=playbook\_cb,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;runner\_callbacks=runner\_cb,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;stats=stats,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sudo=self.\_sudo,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sudo\_user=self.\_sudo\_user,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;private\_key\_file=self.\_private\_key\_file,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;)

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;status = pb.run()

while the code of PlaybookCallbacks contains a lot of `print`  
statements. I could monkey patch ansible.callbacks.banner and  
ansible.callbacks.stringc, but it's very ugly and it will still print  
a newline for each `print` statement.

I wonder if there is a better way to solve this issue, and if there is  
no way currently, I would like to ask you if you would accept a pull  
request to replace the `print` statements with functions that can be  
configured (or overridden).

.a.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [April 19, 2013, 8:26pm UTC](https://forum.ansible.com/t/ansible-api/12702/2 "2013-04-19T20:26:07Z")

</div>

You can subclass the callback or provide your own implementation, or additionally log with an additional logging callback plugin.

---

<div class="post-metadata">

**Author:** ![Antonio\_Messina](https://avatars.discourse-cdn.com/v4/letter/a/9de053/32.png) [@Antonio\_Messina](https://forum.ansible.com/u/Antonio_Messina)\
**Post date:** [April 19, 2013, 9:27pm UTC](https://forum.ansible.com/t/ansible-api/12702/3 "2013-04-19T21:27:56Z")

</div>

I see there is a `DefaultRunnerCallbacks` class that does not print  
anything, wouldn't it nice to have also a `DefaultPlaybookCallbacks`  
that does not print anything as well?

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [April 19, 2013, 9:32pm UTC](https://forum.ansible.com/t/ansible-api/12702/4 "2013-04-19T21:32:14Z")

</div>

Not really, as the main project does not have a use for such things.

You can pass in a class of your own design though.
