# append users to another group

**URL:** <https://forum.ansible.com/t/append-users-to-another-group/21560>\
**Category:** Ansible Project\
**Created:** [May 25, 2016, 10:00am UTC](https://forum.ansible.com/t/append-users-to-another-group/21560 "2016-05-25T10:00:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marc\_Roelofs](https://avatars.discourse-cdn.com/v4/letter/m/a3d4f5/32.png) [@Marc\_Roelofs](https://forum.ansible.com/u/Marc_Roelofs)\
**Post date:** [May 25, 2016, 10:00am UTC](https://forum.ansible.com/t/append-users-to-another-group/21560/1 "2016-05-25T10:00:20Z")

</div>

I am trying to figure out how to generate a list of users on a remote machine who are currently already a member of group A , and append them all to group B  
Is this possible ?

Could not find a way to lookup existing users that are already a member of a group . I would like to be able to do this on different machines which have different users available , so creating a list of users on my ansible management station and using it as input is not an option

Please advice

Best Marc

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [May 25, 2016, 2:55pm UTC](https://forum.ansible.com/t/append-users-to-another-group/21560/2 "2016-05-25T14:55:28Z")

</div>

You can retrieve members of a group using the `getent` module: [http://docs.ansible.com/ansible/getent\_module.html](http://docs.ansible.com/ansible/getent_module.html)

Such as:

- getent: database=group split=‘:’ key=sudo  
register: sudo\_users

- debug: var=sudo\_users.getent\_group.sudo[3]

The output should be a comma separated list. You could make this an actual python list using `sudo_users.getent_group.sudo[3].split(',')`
