# How to get variables from python to Ansible?

**URL:** <https://forum.ansible.com/t/how-to-get-variables-from-python-to-ansible/16150>\
**Category:** Ansible Project\
**Created:** [September 8, 2014, 6:37pm UTC](https://forum.ansible.com/t/how-to-get-variables-from-python-to-ansible/16150 "2014-09-08T18:37:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tiglath](https://avatars.discourse-cdn.com/v4/letter/t/df705f/32.png) [@Tiglath](https://forum.ansible.com/u/Tiglath)\
**Post date:** [September 8, 2014, 6:37pm UTC](https://forum.ansible.com/t/how-to-get-variables-from-python-to-ansible/16150/1 "2014-09-08T18:37:40Z")

</div>

I know that

register: var

Allows to reference var.stdout, but…

Say I call a python script that prints to stdout more than one argument as in a tuple : (arg1, arg2, arg3)

How can I get that into individual variables in Ansible?

Thanks

---

<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:** [September 8, 2014, 7:42pm UTC](https://forum.ansible.com/t/how-to-get-variables-from-python-to-ansible/16150/2 "2014-09-08T19:42:44Z")

</div>

Easiest would be to write a fact module, and return a JSON response that contains the dictionary “ansible\_facts”. Register does not need to be used with these modules.

Take a look at any module in the tree ending in “\_facts” for an example, the setup module is a special case of those, that is called automatically.

–Michael

---

<div class="post-metadata">

**Author:** ![Tiglath](https://avatars.discourse-cdn.com/v4/letter/t/df705f/32.png) [@Tiglath](https://forum.ansible.com/u/Tiglath)\
**Post date:** [September 8, 2014, 10:15pm UTC](https://forum.ansible.com/t/how-to-get-variables-from-python-to-ansible/16150/3 "2014-09-08T22:15:59Z")

</div>

I used the code of the ‘user’ module to try, and it works, unfortunately I wanted to prompt the user for the args and the custom module can’t seem to do an interactive session.

The var\_prompt module is not really suitable, for what I see. I have to get 4 answers and a lot of work to validate them in between, that’s why I think it’s best to do that in Python, then pass to Ansible the arguments to use in the deployment and fire it off. Looks like I’ll have to use --extra\_vars to pass the args to Ansible. Pity, a custom module sounded neat.

Thanks

---

<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:** [September 9, 2014, 4:44pm UTC](https://forum.ansible.com/t/how-to-get-variables-from-python-to-ansible/16150/4 "2014-09-09T16:44:18Z")

</div>

This seems to be a different question.

Since this is about writing modules, would you mind asking on ansible-devel?

Apologies on being the list cop but this is a very active list, and I also want to encourage the devel list a bit.

Thanks!
