Python API -> Inventory Variables

66 views
Skip to first unread message

CJR

unread,
Sep 30, 2014, 2:11:01 PM9/30/14
to ansible...@googlegroups.com
All -

I am having hell with this:

getLog = ansible.runner.Runner(
forks
=100,
inventory
=ansible.inventory.Inventory('inventory'),
module_name
='fetch',
module_args
='src=/tmp/logs.tar.gz dest=./output/?????????/logs flat=yes validate_md5=no',
).run()

In line 5, you can see I put a whole bunch of ?????????.  If I were writing a playbook, I would have something like {{ ansible_ssh_host }} there. 
I want the IP address of the target so that when everything is done, I have all my server logs back on my machine.

I have verified, the logs (/tmp/logs.tar.gz) ARE there, and if I try and fetch them without a varible it works...but they all overwrite each other. 

Anybody have an idea??
Thanks!

Michael DeHaan

unread,
Oct 1, 2014, 8:05:23 AM10/1/14
to ansible...@googlegroups.com
First off, what's ansible --version?

Second, can you show the line you have tried using the variable?

This is a more-appropriate question for ansible-devel in the future.  

Thanks!


--
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/b591d1fa-7947-4698-8d3c-e483df418a7d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Matt Martz

unread,
Oct 1, 2014, 8:44:49 AM10/1/14
to ansible...@googlegroups.com
So, reducing this to a more simple example:

getLog = ansible.runner.Runner(
    forks=100,
    inventory=ansible.inventory.Inventory('inventory'),
    module_name='command',
    module_args='echo "{{ansible_ssh_host|default(inventory_hostname)}}"',
).run()

In the above, I can confirm that standard variable replacement, just as used in a playbook, work as expected here:

{'dark': {}, 'contacted': {'127.0.0.1': {u'cmd': [u'echo', u'127.0.0.1'], u'end': u'2014-10-01 07:40:29.208210', u'stdout': u'127.0.0.1', u'changed': True, u'start': u'2014-10-01 07:40:29.202530', u'delta': u'0:00:00.005680', u'stderr': u'', u'rc': 0, 'invocation': {'module_name': 'command', 'module_args': u'echo "127.0.0.1"'}}}}

--
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/b591d1fa-7947-4698-8d3c-e483df418a7d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Matt Martz
@sivel
sivel.net

CJR

unread,
Oct 1, 2014, 8:46:23 AM10/1/14
to ansible...@googlegroups.com
I am running Ansible version 1.7.

I have tried many different flavors of variables.  I have tried using Ansiable syntax:

module_args='src=/tmp/logs.tar.gz dest=./output/{{ inventory_hostname }}/logs

...as I would in a YML playbook.

CJR

unread,
Oct 1, 2014, 8:47:39 AM10/1/14
to ansible...@googlegroups.com
Matt -

Thanks for the assistance.  I will try that shortly and see if I get the desired effect.  I hadn't been using default() around it...

CJR

unread,
Oct 1, 2014, 10:34:14 AM10/1/14
to ansible...@googlegroups.com
This did it!  Thanks, I was not including the '|default(...)' piece. 


On Wednesday, October 1, 2014 8:44:49 AM UTC-4, Matt Martz wrote:
Reply all
Reply to author
Forward
0 new messages