# Running ansible from python

**URL:** <https://forum.ansible.com/t/running-ansible-from-python/22447>\
**Category:** Ansible Project\
**Created:** [September 1, 2016, 10:26am UTC](https://forum.ansible.com/t/running-ansible-from-python/22447 "2016-09-01T10:26:39Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ankur.cool](https://avatars.discourse-cdn.com/v4/letter/a/f08c70/32.png) [@ankur.cool](https://forum.ansible.com/u/ankur.cool)\
**Post date:** [September 1, 2016, 10:26am UTC](https://forum.ansible.com/t/running-ansible-from-python/22447/1 "2016-09-01T10:26:39Z")

</div>

Hi

I have a need to call ansible from python. I was looking at [http://docs.ansible.com/ansible/developing\_api.html#python-api-2-0](http://docs.ansible.com/ansible/developing_api.html#python-api-2-0) but doc doesn’t seem to be very clear.

I need to execute a module or a playbook which ever is easy and want the response of it. Basically this is my custom module which returns me a list of services running on my servers.

Please see that I have lots of variables defined in my group\_vars have lots of custom roles in my ansible directory (Having directory structure as specified in ansible docs).  
So I want that when I execute module or playbook from python it should be able to use these vars, roles, etc…

Also I am not sure how can I get the output of executing the api so that I can process that data in python

Hope I can find some answers here. Please let me know if I am not clear with requirement.

Thanks
