# vars merging

**URL:** <https://forum.ansible.com/t/vars-merging/12573>\
**Category:** Ansible Project\
**Tags:** ansible-project\
**Created:** [March 25, 2013, 7:00am UTC](https://forum.ansible.com/t/vars-merging/12573 "2013-03-25T07:00:17Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![C\_Morgan\_Hamill](https://avatars.discourse-cdn.com/v4/letter/c/ebca7d/32.png) [@C\_Morgan\_Hamill](https://forum.ansible.com/u/C_Morgan_Hamill)\
**Post date:** [March 25, 2013, 7:00am UTC](https://forum.ansible.com/t/vars-merging/12573/1 "2013-03-25T07:00:17Z")

</div>

In ansible.cfg, under the '[defaults]' section, you can put 'hash\_behavior = merge'. I think this is new as of the pending 1.1 release, so you'll need a gift checkout.

See \<[https://github.com/ansible/ansible/blob/devel/examples/ansible.cfg&gt](https://github.com/ansible/ansible/blob/devel/examples/ansible.cfg&gt); for an example config file.

---

<div class="post-metadata">

**Author:** ![C\_Morgan\_Hamill](https://avatars.discourse-cdn.com/v4/letter/c/ebca7d/32.png) [@C\_Morgan\_Hamill](https://forum.ansible.com/u/C_Morgan_Hamill)\
**Post date:** [March 25, 2013, 6:29pm UTC](https://forum.ansible.com/t/vars-merging/12573/2 "2013-03-25T18:29:47Z")

</div>

Excerpts from seb.stark's message of 2013-03-25 10:17:18 -0400:

> Thanks for noting! Is this also possible for lists?

I don't believe so.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [March 25, 2013, 6:56pm UTC](https://forum.ansible.com/t/vars-merging/12573/3 "2013-03-25T18:56:09Z")

</div>

Nope, there's no good way to tell what behavior you would want with lists.

---

<div class="post-metadata">

**Author:** ![seb.stark](https://avatars.discourse-cdn.com/v4/letter/s/e9c0ed/32.png) [@seb.stark](https://forum.ansible.com/u/seb.stark)\
**Post date:** [March 26, 2013, 7:44am UTC](https://forum.ansible.com/t/vars-merging/12573/4 "2013-03-26T07:44:40Z")

</div>

My use case is a packages variable in group\_vars/all that I want to append to in group\_vars/\<group\> and host\_vars/\<host\>. So far I use two more variables (group\_packages and host\_packages), that default to and separate actions for using them.

But maybe there is already a better way to do this?

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [March 26, 2013, 12:49pm UTC](https://forum.ansible.com/t/vars-merging/12573/5 "2013-03-26T12:49:27Z")

</div>

Your approach would work, though if hosts were in more than one group,  
that doesn't work so much.

Generally I find the purpose of plays though to bind hosts to roles,  
so the individual roles should contain the package lists.

I would not try to store everything in variables that way.

In fact, you should almost never have host specific variables related  
to behavior -- networking and hardware configurations yes, but very  
seldom behavior.

---

<div class="post-metadata">

**Author:** ![seb.stark](https://avatars.discourse-cdn.com/v4/letter/s/e9c0ed/32.png) [@seb.stark](https://forum.ansible.com/u/seb.stark)\
**Post date:** [March 26, 2013, 4:01pm UTC](https://forum.ansible.com/t/vars-merging/12573/6 "2013-03-26T16:01:53Z")

</div>

Good point. I already noticed my system isn’t working well because I have roles that add yet more packages to individual hosts. In fact, those explicit package lists are the only contents of my host\_vars/\* files and I should really get rid of them. Thanks for the heads up!
