# Merging of host\_vars and group\_vars?

**URL:** <https://forum.ansible.com/t/merging-of-host-vars-and-group-vars/15895>\
**Category:** Ansible Project\
**Tags:** galaxy-ng\
**Created:** [August 8, 2014, 6:36pm UTC](https://forum.ansible.com/t/merging-of-host-vars-and-group-vars/15895 "2014-08-08T18:36:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ryan2](https://avatars.discourse-cdn.com/v4/letter/r/7ab992/32.png) [@ryan2](https://forum.ansible.com/u/ryan2)\
**Post date:** [August 8, 2014, 6:36pm UTC](https://forum.ansible.com/t/merging-of-host-vars-and-group-vars/15895/1 "2014-08-08T18:36:06Z")

</div>

I have a playbook with a role that creates users that are defined in group\_vars/all, similar to this role [https://galaxy.ansible.com/list#/roles/51](https://galaxy.ansible.com/list#/roles/51). When I define a user in the host\_vars/foo it takes over precedence and does not add the users I have in group\_vars/all. I have set hash\_behaviour = merge in my ansible.cfg. Is this expected behavior? My use case is I have my sysadmin users defined in group\_vars/all that should be present on all hosts and I want to give access to a dev on the foo host only. Is there a better way to approach this?

group\_vars/all

```auto
users:
 - username: sysadmin
   name: sysadmin
   groups: ['sysadmin']
   uid: 1001
   ssh_key:
     - "ssh-rsa AAAA.....ZZZZ"

```

host\_vars/foo

```auto
users:
 - username: dev
   name: dev
   groups: ['dev']
   uid: 2001
   ssh_key:
     - "ssh-rsa AAAA.....ZZZZ"

```

Thanks.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [August 8, 2014, 11:31pm UTC](https://forum.ansible.com/t/merging-of-host-vars-and-group-vars/15895/2 "2014-08-08T23:31:32Z")

</div>

hash\_merge would only merge hashes, not lists.

So if you instead had users keyed such that they were in the hash based on the username, that would work.

users:  
dev:  
name: dev  
groups: [‘dev’]  
uid: 2001

etc

The extra “name” may also be redundant, but this should get you on the right track.
