How to get variables from python to Ansible?

142 views
Skip to first unread message

Tiglath

unread,
Sep 8, 2014, 2:37:40 PM9/8/14
to ansible...@googlegroups.com
 
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
 
 
 
 

Michael DeHaan

unread,
Sep 8, 2014, 3:42:48 PM9/8/14
to ansible...@googlegroups.com
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

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/09e3b12b-acda-4a70-8c53-61132cc298db%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Tiglath

unread,
Sep 8, 2014, 6:15:59 PM9/8/14
to ansible...@googlegroups.com
 
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

Michael DeHaan

unread,
Sep 9, 2014, 12:44:21 PM9/9/14
to ansible...@googlegroups.com
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!

Reply all
Reply to author
Forward
0 new messages