# list of variables in YAML inventory

**URL:** <https://forum.ansible.com/t/list-of-variables-in-yaml-inventory/25578>\
**Category:** Ansible Project\
**Created:** [September 22, 2017, 4:23pm UTC](https://forum.ansible.com/t/list-of-variables-in-yaml-inventory/25578 "2017-09-22T16:23:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![bundyboyuk](https://avatars.discourse-cdn.com/v4/letter/b/4bbf92/32.png) [@bundyboyuk](https://forum.ansible.com/u/bundyboyuk)\
**Post date:** [September 22, 2017, 4:23pm UTC](https://forum.ansible.com/t/list-of-variables-in-yaml-inventory/25578/1 "2017-09-22T16:23:35Z")

</div>

Hi,

I am running Ansible from a python script and I want to iterate over a dynamic list created in the python script. The inventory is also dynamically created in this script. The list is different for each host Ansible is connecting to. I don’t want to put the list into the host\_vars where I want to keep only static variables. So I tried to put these variables in my dynamically created yaml inventory for each host. This does not seem to work, ansible says the list is not defined. However if I put the list in the group, it is working:

**this is not working**

`  
ma:  
hosts:  
maman1-lab:  
vars:  
devicesids:

- d46798753  
maman2-lab:  
vars:  
devicesids:
- d46798752  
`

**But this is working (but not what I want)**

`  
ma:  
hosts:  
maman1-lab:  
maman2-lab:  
vars:  
devicesids:

- d46798752
- d46798753

`

Is it possible to associate a list of vars to a single host and not to an entire group?

thanks

Bundy

---

<div class="post-metadata">

**Author:** ![Soniya\_panwar](https://avatars.discourse-cdn.com/v4/letter/s/22d042/32.png) [@Soniya\_panwar](https://forum.ansible.com/u/Soniya_panwar)\
**Post date:** [October 24, 2017, 5:16am UTC](https://forum.ansible.com/t/list-of-variables-in-yaml-inventory/25578/2 "2017-10-24T05:16:12Z")

</div>

Hello Bundy,

You may use a regular text file for each host to contain the dynamically created list you wish to iterate over. This text file can then be consumed in playbook using the lookup plugin. Lookup plugins allow accessing data in Ansible from the filesystem. Below is the sample example :
