# Returning a value from my playbook to the python client

**URL:** <https://forum.ansible.com/t/returning-a-value-from-my-playbook-to-the-python-client/17333>\
**Category:** Ansible Developer\
**Created:** [January 20, 2015, 11:12pm UTC](https://forum.ansible.com/t/returning-a-value-from-my-playbook-to-the-python-client/17333 "2015-01-20T23:12:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ritesh\_Shetty](https://avatars.discourse-cdn.com/v4/letter/r/839c29/32.png) [@Ritesh\_Shetty](https://forum.ansible.com/u/Ritesh_Shetty)\
**Post date:** [January 20, 2015, 11:12pm UTC](https://forum.ansible.com/t/returning-a-value-from-my-playbook-to-the-python-client/17333/1 "2015-01-20T23:12:54Z")

</div>

Hi All,  
I am using the python api to call the playbook. Something like this

pb = ansible.playbook.PlayBook(  
playbook=playbook,  
remote\_pass=sshpass,  
callbacks=playbook\_cb,  
runner\_callbacks=runner\_cb,  
stats=stats,  
sudo\_pass=sudopass,  
extra\_vars=extra\_vars,  
su\_pass=su\_pass,  
vault\_password=vault\_pass,  
private\_key\_file=private\_key\_file,  
)

Problem is i need to return a value from one of my tasks to this calling code (client) Is there any elegant way of doing it(other than dumping value in temporary file or setting it in environment variable) ?

Regards  
Ritesh

---

<div class="post-metadata">

**Author:** ![Giovanni\_Tirloni](https://avatars.discourse-cdn.com/v4/letter/g/71c47a/32.png) [@Giovanni\_Tirloni](https://forum.ansible.com/u/Giovanni_Tirloni)\
**Post date:** [January 20, 2015, 11:53pm UTC](https://forum.ansible.com/t/returning-a-value-from-my-playbook-to-the-python-client/17333/2 "2015-01-20T23:53:01Z")

</div>

It seems you could use the functions exit\_json / fail\_json in your  
module to return additional data in JSON format.

[https://github.com/ansible/ansible/blob/devel/lib/ansible/module\_utils/basic.py](https://github.com/ansible/ansible/blob/devel/lib/ansible/module_utils/basic.py)  
[http://docs.ansible.com/developing\_modules.html#common-module-boilerplate](http://docs.ansible.com/developing_modules.html#common-module-boilerplate)

Have you considered developing a plugin and hooking into events you want  
to handle?

Giovanni

ps.: I'm an Ansible newbie. Be warned.

---

<div class="post-metadata">

**Author:** ![Ritesh\_Shetty](https://avatars.discourse-cdn.com/v4/letter/r/839c29/32.png) [@Ritesh\_Shetty](https://forum.ansible.com/u/Ritesh_Shetty)\
**Post date:** [January 21, 2015, 3:58am UTC](https://forum.ansible.com/t/returning-a-value-from-my-playbook-to-the-python-client/17333/3 "2015-01-21T03:58:07Z")

</div>

Thanks Giovanni , i have implemented the callback plugins. I am also using the module.exit\_json , but didnt realize this can be used to send back the data. I have now trapped the runner\_on\_ok and get the return value. Thanks for the info it worked
