# yet another question about loops

**URL:** <https://forum.ansible.com/t/yet-another-question-about-loops/17794>\
**Category:** Ansible Project\
**Created:** [March 19, 2015, 8:00pm UTC](https://forum.ansible.com/t/yet-another-question-about-loops/17794 "2015-03-19T20:00:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![user66](https://avatars.discourse-cdn.com/v4/letter/u/b487fb/32.png) [@user66](https://forum.ansible.com/u/user66)\
**Post date:** [March 19, 2015, 8:00pm UTC](https://forum.ansible.com/t/yet-another-question-about-loops/17794/1 "2015-03-19T20:00:17Z")

</div>

yet another question about loops

I want to be able to merge users across servers.  
For example,  
I want user1 to be on all of my hosts  
and I want user\_special\_at\_office to be only at my office’s servers

So I made inventory file, where I specified all of the groups.  
I made group\_vars for **all** and for **office**

As I’ve read I can merge only dictionaries.

file group\_vars/all

---

<div class="post-metadata">

**Author:** ![vaida.dan](https://avatars.discourse-cdn.com/v4/letter/v/5daacb/32.png) [@vaida.dan](https://forum.ansible.com/u/vaida.dan)\
**Post date:** [March 21, 2015, 4:21pm UTC](https://forum.ansible.com/t/yet-another-question-about-loops/17794/2 "2015-03-21T16:21:30Z")

</div>

There are various ways you could go about doing this. Here’s one of them.  
users.yml

`

---

<div class="post-metadata">

**Author:** ![user66](https://avatars.discourse-cdn.com/v4/letter/u/b487fb/32.png) [@user66](https://forum.ansible.com/u/user66)\
**Post date:** [March 26, 2015, 2:14pm UTC](https://forum.ansible.com/t/yet-another-question-about-loops/17794/3 "2015-03-26T14:14:38Z")

</div>

Thanks, Dan!  
I’ve managed to do what I wanted with you help.  
I ended up with:  
setting hash\_behaviour = merge in ansible.cfg

group\_vars/all

`

users:  
user1:  
comment: “user1”  
state: “present”  
groups:

- “wheel”
- “dvp”  
authorized:
- “ssh-rsa 111”
- “ssh-rsa 222”  
user2:  
comment: “user2”  
state: ‘absent’  
groups:
- “wheel”
- “dvp”  
authorized:
- “ssh-rsa 333”  
user3:  
comment: “user3”  
state: ‘absent’  
groups:
- “wheel”
- “dvp”  
authorized:
- “ssh-rsa 123”  
user4:  
comment: “user4”  
state: ‘absent’  
groups:
- “dvp”  
authorized:
- “ssh-rsa 555”

`

group\_vars/office

`
