# Create different users on different hosts

**URL:** <https://forum.ansible.com/t/create-different-users-on-different-hosts/24963>\
**Category:** Ansible Project\
**Created:** [July 12, 2017, 1:49pm UTC](https://forum.ansible.com/t/create-different-users-on-different-hosts/24963 "2017-07-12T13:49:08Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Frank2](https://avatars.discourse-cdn.com/v4/letter/f/f9ae1b/32.png) [@Frank2](https://forum.ansible.com/u/Frank2)\
**Post date:** [July 12, 2017, 1:49pm UTC](https://forum.ansible.com/t/create-different-users-on-different-hosts/24963/1 "2017-07-12T13:49:08Z")

</div>

Hi,

I’ve got various servers to manage which belong to different departments. Also one server could belong to multiple departments.  
I would like to create the admin users on all servers, and additional users depending on the departments that the server belongs to (like development).  
All of this by looping over group\_var files which contain the user information.

Simplified example:

inventory file:  
file “hosts”:  
[servers]  
srv1  
srv2

[dep1]  
srv2

[dep2]  
srv2

group\_vars:  
file “all”:  
users:  
admin1:  
comment: “Admin user 1”

file “dep1”:  
users:  
dep1:  
comment: “Department1 user”

file “dep2”:  
users:  
dep2:  
comment: “Department2 user”

task:  
file “users.yml”:

- name: Create users  
user:  
name: “{{item.key}}”  
comment: “{{item.value.comment}}”  
with\_dict: “{{ users }}”

So “srv2” belongs to groups “all”, “dep1” and “dep2”, hence the users “admin1”, “dep1” and “dep2” should be created on “srv2”  
But only user “dep2” will be created, because this is the last file through which ansible is looping in alphabetical order.  
If I would rename the file “dep1” to “ZZZdep1” this would be the last file, and user “dep1” would be created.

I can’t find a way to achieve this, any help appreciated.

Cheers,  
Frank

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [July 14, 2017, 2:55pm UTC](https://forum.ansible.com/t/create-different-users-on-different-hosts/24963/2 "2017-07-14T14:55:37Z")

</div>

You could have a look at hash\_behaviour = merge  
[https://docs.ansible.com/ansible/intro\_configuration.html#hash-behaviour](https://docs.ansible.com/ansible/intro_configuration.html#hash-behaviour)
