# List in inventory file variables ?

**URL:** <https://forum.ansible.com/t/list-in-inventory-file-variables/17627>\
**Category:** Ansible Project\
**Created:** [February 26, 2015, 12:08pm UTC](https://forum.ansible.com/t/list-in-inventory-file-variables/17627 "2015-02-26T12:08:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Florent\_B](https://avatars.discourse-cdn.com/v4/letter/f/7ba0ec/32.png) [@Florent\_B](https://forum.ansible.com/u/Florent_B)\
**Post date:** [February 26, 2015, 12:08pm UTC](https://forum.ansible.com/t/list-in-inventory-file-variables/17627/1 "2015-02-26T12:08:53Z")

</div>

Hi,

I would like to write a complex variable (list) for each host in my inventory file.  
I know it’s not a best practice, but I cannot write a vars file per host (constrained by project).

So I tried something like this :

[my-hosts]  
192.168.0.161 pub=[{ip:‘192.168.0.162’,proto:‘tcp’},{ip:‘192.168.0.163’,proto:‘tcp’}]

But it does not seem to work, I cannot use it in with\_indexed\_items for example. Variable seems to be treated as a string.  
It returns “with\_indexed\_items expects a list”.

How can I do ?

I use Ansible 1.8.4

Thank you a lot.

---

<div class="post-metadata">

**Author:** ![Serge\_van\_Ginderacht](https://avatars.discourse-cdn.com/v4/letter/s/b782af/32.png) [@Serge\_van\_Ginderacht](https://forum.ansible.com/u/Serge_van_Ginderacht)\
**Post date:** [February 26, 2015, 12:14pm UTC](https://forum.ansible.com/t/list-in-inventory-file-variables/17627/2 "2015-02-26T12:14:58Z")

</div>

​Don't define complex vars in the ini hosts file, use group/host\_vars file​  
or playbook vars for that.

---

<div class="post-metadata">

**Author:** ![Tomasz\_Kontusz](https://avatars.discourse-cdn.com/v4/letter/t/bc79bd/32.png) [@Tomasz\_Kontusz](https://forum.ansible.com/u/Tomasz_Kontusz)\
**Post date:** [February 27, 2015, 8:20am UTC](https://forum.ansible.com/t/list-in-inventory-file-variables/17627/3 "2015-02-27T08:20:01Z")

</div>

If you have to generate exactly one file, you can try creating a dynamic inventory

Florent B [florent@coppint.com](mailto:florent@coppint.com) napisał:
