# Same list from multiple vars-files consolidated

**URL:** <https://forum.ansible.com/t/same-list-from-multiple-vars-files-consolidated/17207>\
**Category:** Ansible Project\
**Created:** [January 7, 2015, 1:59pm UTC](https://forum.ansible.com/t/same-list-from-multiple-vars-files-consolidated/17207 "2015-01-07T13:59:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sebastian\_Gumprich](https://avatars.discourse-cdn.com/v4/letter/s/a6a055/32.png) [@Sebastian\_Gumprich](https://forum.ansible.com/u/Sebastian_Gumprich)\
**Post date:** [January 7, 2015, 1:59pm UTC](https://forum.ansible.com/t/same-list-from-multiple-vars-files-consolidated/17207/1 "2015-01-07T13:59:28Z")

</div>

Hello,

I have a list-item in the group-vars for “all” hosts:

`  
“/etc/ansible/group\_vars/all”

` `

splunkforwarder\_log\_items:

- app\_name: var\_messages  
source: “/var/log/messages”

`

I also have the same list-item in another (narrowed down) group-var:

`  
“/etc/ansible/group\_vars/group\_1”

` `  
splunkforwarder\_log\_items:

- app\_name: var\_secure  
source: “/var/log/secure”  
index: “testindex”  
sourcetype: linux\_secure

`

Now I want to use both lists (or the conflated list) in the following task, so `{{ item.app_name }}` would be substituted with `var_messages`  
`and ``var_secure from both lists.`

`

- name: create input configuration  
template:  
src=inputs\_conf.j2  
dest=/etc/apps/{{ item.app\_name }}/local/inputs.conf  
with\_items: splunkforwarder\_log\_items

`

Sadly, only the list from “group\_1” is used.  
Is there a way to conflate these lists / use both? Or am I doing something wrong?

Regards  
Sebastian

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [January 7, 2015, 2:11pm UTC](https://forum.ansible.com/t/same-list-from-multiple-vars-files-consolidated/17207/2 "2015-01-07T14:11:27Z")

</div>

ansible by default will override previous definitions with newer ones,  
in this case group 'all' gets loaded first and then overwritten by  
group1.

You can change this behavior globally using the hash\_behaviour entry  
in ansible.cfg.  
Or you can name the variable differently and then use the |union  
filter in the task to aggregate them just for that task.

---

<div class="post-metadata">

**Author:** ![Sebastian\_Gumprich](https://avatars.discourse-cdn.com/v4/letter/s/a6a055/32.png) [@Sebastian\_Gumprich](https://forum.ansible.com/u/Sebastian_Gumprich)\
**Post date:** [January 8, 2015, 8:18am UTC](https://forum.ansible.com/t/same-list-from-multiple-vars-files-consolidated/17207/3 "2015-01-08T08:18:41Z")

</div>

Thanks for your input.  
I tried setting hash\_behaviour to “merge” but this doesn’t work. Even when I put the two lists into one vars-file, only the last list will be used.  
But you mentioning naming the variable different gave me an idea. I’m using different variables in group\_vars and host\_vars now and use multiple tasks and templates.

Thanks!

---

<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:** [January 8, 2015, 8:53am UTC](https://forum.ansible.com/t/same-list-from-multiple-vars-files-consolidated/17207/4 "2015-01-08T08:53:33Z")

</div>

Sebastian Gumprich \<zufallsheld@gmail.com\> napisał:

> Thanks for your input.  
> I tried setting hash\_behaviour to "merge" but this doesn't work.

hash\_behaviour only affects dictionaries

> Even when  
> I put the two lists into one vars-file, only the last list will be  
> used.

Repeated keys in a dictionary is implementation-defined in YAML, and PyYaml (the library Ansible uses) just ignores all but the last repeated key.
