# add list from host variables and group variables

**URL:** <https://forum.ansible.com/t/add-list-from-host-variables-and-group-variables/30423>\
**Category:** Ansible Project\
**Created:** [May 25, 2019, 6:42pm UTC](https://forum.ansible.com/t/add-list-from-host-variables-and-group-variables/30423 "2019-05-25T18:42:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marc\_Haber](https://avatars.discourse-cdn.com/v4/letter/m/a3d4f5/32.png) [@Marc\_Haber](https://forum.ansible.com/u/Marc_Haber)\
**Post date:** [May 25, 2019, 6:42pm UTC](https://forum.ansible.com/t/add-list-from-host-variables-and-group-variables/30423/1 "2019-05-25T18:42:45Z")

</div>

Hi,

this is what I have in a YAML formatted inventory

---

<div class="post-metadata">

**Author:** ![Sebastian\_Meyer](https://avatars.discourse-cdn.com/v4/letter/s/779978/32.png) [@Sebastian\_Meyer](https://forum.ansible.com/u/Sebastian_Meyer)\
**Post date:** [May 27, 2019, 8:21am UTC](https://forum.ansible.com/t/add-list-from-host-variables-and-group-variables/30423/2 "2019-05-27T08:21:06Z")

</div>

Hi Marc,

> this is what I have in a YAML formatted inventory
> 
> ---  
> all:  
> &nbsp;&nbsp;vars:  
> &nbsp;&nbsp;&nbsp;&nbsp;city:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- Berlin  
> &nbsp;&nbsp;children:  
> &nbsp;&nbsp;&nbsp;&nbsp;g\_empty:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hosts:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;emptybuster:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;emptysid:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;emptystretch:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;city:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- Steglitz
> 
> Is there a more elegant way to do this, or have I reached ansible's  
> limits? If so, is there a bug report against ansible where I could read  
> up on the situation?

Well, Ansibles variable system isn't as featureful as e.g. hiera and  
works mostly with overwrites.

I see two possibilities here:

1. Using the a lookup plugin, not inventory variables, e.g. hiera since  
it supports all kinds of merging

[https://docs.ansible.com/ansible/latest/plugins/lookup/hiera.html](https://docs.ansible.com/ansible/latest/plugins/lookup/hiera.html)

2. Use a different name for the variables and use set\_fact in your  
playbook/a role to merge them.
