# retrieving the inventory name from the job template

**URL:** <https://forum.ansible.com/t/retrieving-the-inventory-name-from-the-job-template/32264>\
**Category:** AWX Project\
**Tags:** awx\
**Created:** [February 19, 2020, 12:58am UTC](https://forum.ansible.com/t/retrieving-the-inventory-name-from-the-job-template/32264 "2020-02-19T00:58:36Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dave\_York](https://avatars.discourse-cdn.com/v4/letter/d/77aa72/32.png) [@Dave\_York](https://forum.ansible.com/u/Dave_York)\
**Post date:** [February 19, 2020, 12:58am UTC](https://forum.ansible.com/t/retrieving-the-inventory-name-from-the-job-template/32264/1 "2020-02-19T00:58:36Z")

</div>

Hi Ansible/AWX Community!

I’m working on a project that builds an on-premesis virtual machine then adds it to a tower inventory.

I have a job template that runs against “Inventory X”. How can I retrieve the name of the tower inventory this job was run against (Inventory X), so that I can add this new host to that inventory?

---

<div class="post-metadata">

**Author:** ![Nuno\_Jordao](https://avatars.discourse-cdn.com/v4/letter/n/a4c791/32.png) [@Nuno\_Jordao](https://forum.ansible.com/u/Nuno_Jordao)\
**Post date:** [February 19, 2020, 2:43am UTC](https://forum.ansible.com/t/retrieving-the-inventory-name-from-the-job-template/32264/2 "2020-02-19T02:43:38Z")

</div>

Hello,

Isn’t the tower\_inventory\_name or tower\_inventory\_id available?

[https://docs.ansible.com/ansible-tower/latest/html/userguide/job\_templates.html](https://docs.ansible.com/ansible-tower/latest/html/userguide/job_templates.html)

Regards,

Nuno Jordão

---

<div class="post-metadata">

**Author:** ![Dave\_York](https://avatars.discourse-cdn.com/v4/letter/d/77aa72/32.png) [@Dave\_York](https://forum.ansible.com/u/Dave_York)\
**Post date:** [February 19, 2020, 3:03am UTC](https://forum.ansible.com/t/retrieving-the-inventory-name-from-the-job-template/32264/3 "2020-02-19T03:03:52Z")

</div>

Hmm -  
If I use  
‘{{ lookup(“env”, “tower\_inventory\_name”) }}’  
I get

TASK [debug] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
18:59:49

11  
ok: [localhost] =\> {

12  
“msg”: “”

13  
}

14

If I use just {{ tower\_inventory\_name }}  
I get

> The task includes an option with an undefined variable. The error was: ‘tower\_inventory\_name’ is undefined

Apologies if I’m doing something stupid I’m only about a month into ansible

---

<div class="post-metadata">

**Author:** ![AlanCoding](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/alancoding/32/301_2.png) [@AlanCoding](https://forum.ansible.com/u/AlanCoding)\
**Post date:** [February 19, 2020, 3:48am UTC](https://forum.ansible.com/t/retrieving-the-inventory-name-from-the-job-template/32264/4 "2020-02-19T03:48:57Z")

</div>

It should work without the lookup, it’s intended here:

[https://github.com/ansible/awx/blob/devel/awx/main/models/unified\_jobs.py#L1442](https://github.com/ansible/awx/blob/devel/awx/main/models/unified_jobs.py#L1442)

and I can easily find it in the Ansible Tower docs. We even have a unit test for it as awx\_inventory\_name.

Alan  
github: AlanCoding

---

<div class="post-metadata">

**Author:** ![Dave\_York](https://avatars.discourse-cdn.com/v4/letter/d/77aa72/32.png) [@Dave\_York](https://forum.ansible.com/u/Dave_York)\
**Post date:** [February 19, 2020, 4:35am UTC](https://forum.ansible.com/t/retrieving-the-inventory-name-from-the-job-template/32264/5 "2020-02-19T04:35:50Z")

</div>

my playbook: —

- hosts: localhost  
connection: local  
gather\_facts: yes

tasks:

- debug:  
var: extra\_vars, tower\_inventory\_name  
verbosity: 1  
-truncated-

The output:

TASK [debug] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
20:27:21

11  
ok: [localhost] =\> {

12  
“extra\_vars, tower\_inventory\_name”: “(AnsibleUndefined, AnsibleUndefined)”

13  
}

14

---

<div class="post-metadata">

**Author:** ![AlanCoding](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/alancoding/32/301_2.png) [@AlanCoding](https://forum.ansible.com/u/AlanCoding)\
**Post date:** [February 19, 2020, 1:24pm UTC](https://forum.ansible.com/t/retrieving-the-inventory-name-from-the-job-template/32264/6 "2020-02-19T13:24:22Z")

</div>

I cannot reproduce. Here is a playbook I wrote for testing this:

[https://github.com/AlanCoding/utility-playbooks/blob/master/meta\_vars.yml](https://github.com/AlanCoding/utility-playbooks/blob/master/meta_vars.yml)

I see the inventory name in its output.

 ![Screen Shot 2020-02-19 at 8.20.32 AM.png](https://us1.discourse-cdn.com/ansible/original/2X/6/6e98ba6381c40f1414177ae42b3d633fec37627b.png)

It is expected that the workflow name is missing (because it was not run in a workflow). Everything else seems to be functioning correctly.

This functionality was added in 6.1.0, so maybe you’re running an old version?
