# Python API -\> Inventory Variables

**URL:** <https://forum.ansible.com/t/python-api-inventory-variables/16386>\
**Category:** Ansible Project\
**Created:** [September 30, 2014, 6:11pm UTC](https://forum.ansible.com/t/python-api-inventory-variables/16386 "2014-09-30T18:11:01Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![CJR](https://avatars.discourse-cdn.com/v4/letter/c/5fc32e/32.png) [@CJR](https://forum.ansible.com/u/CJR)\
**Post date:** [September 30, 2014, 6:11pm UTC](https://forum.ansible.com/t/python-api-inventory-variables/16386/1 "2014-09-30T18:11:01Z")

</div>

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!

---

<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:** [October 1, 2014, 12:05pm UTC](https://forum.ansible.com/t/python-api-inventory-variables/16386/2 "2014-10-01T12:05:19Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [October 1, 2014, 12:44pm UTC](https://forum.ansible.com/t/python-api-inventory-variables/16386/3 "2014-10-01T12:44:06Z")

</div>

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”'}}}}

---

<div class="post-metadata">

**Author:** ![CJR](https://avatars.discourse-cdn.com/v4/letter/c/5fc32e/32.png) [@CJR](https://forum.ansible.com/u/CJR)\
**Post date:** [October 1, 2014, 12:46pm UTC](https://forum.ansible.com/t/python-api-inventory-variables/16386/4 "2014-10-01T12:46:23Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![CJR](https://avatars.discourse-cdn.com/v4/letter/c/5fc32e/32.png) [@CJR](https://forum.ansible.com/u/CJR)\
**Post date:** [October 1, 2014, 12:47pm UTC](https://forum.ansible.com/t/python-api-inventory-variables/16386/5 "2014-10-01T12:47:39Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![CJR](https://avatars.discourse-cdn.com/v4/letter/c/5fc32e/32.png) [@CJR](https://forum.ansible.com/u/CJR)\
**Post date:** [October 1, 2014, 2:34pm UTC](https://forum.ansible.com/t/python-api-inventory-variables/16386/6 "2014-10-01T14:34:14Z")

</div>

This did it! Thanks, I was not including the ‘|default(…)’ piece.
