# Best approach to add or remove users to match list

**URL:** <https://forum.ansible.com/t/best-approach-to-add-or-remove-users-to-match-list/14326>\
**Category:** Ansible Project\
**Created:** [January 11, 2014, 11:25pm UTC](https://forum.ansible.com/t/best-approach-to-add-or-remove-users-to-match-list/14326 "2014-01-11T23:25:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Randolph\_Kahle](https://avatars.discourse-cdn.com/v4/letter/r/e56c9b/32.png) [@Randolph\_Kahle](https://forum.ansible.com/u/Randolph_Kahle)\
**Post date:** [January 11, 2014, 11:25pm UTC](https://forum.ansible.com/t/best-approach-to-add-or-remove-users-to-match-list/14326/1 "2014-01-11T23:25:20Z")

</div>

I am using a list of users to define the exact set of user accounts I need on all of my managed compute instances.

For example:

users:

- {name: randy, group: admin, shell: /bin/bash, uid: 1000, sshkey: /files/users/randy\_rsa.pub, … }
- {name: teresa, group: admin, shell: /bin/bash, uid: 1001, sshkey: /files/users/teresa\_rsa.pub, … }
- {name: mircea, group: admin, shell: /bin/bash, uid: 1002, sshkey: /files/users/mircea\_rsa.pub, … }

I would like to be able to add or remove users from this list and have the user accounts modified on all systems to match this list.

What this means is:

- If a /home/user-unwanted is found, it should be removed
- if a /home/user-wanted is not found, it should be added

otherwise, the user accounts should not be touched.

What is the best practice approach to obtaining two lists (the list of /home/\* directories) and the above list in a variable file, and making only the changes needed to make these list match each other?

Thanks – Randy

---

<div class="post-metadata">

**Author:** ![Jurgen\_Haas2](https://avatars.discourse-cdn.com/v4/letter/j/f0a364/32.png) [@Jurgen\_Haas2](https://forum.ansible.com/u/Jurgen_Haas2)\
**Post date:** [January 14, 2014, 5:35pm UTC](https://forum.ansible.com/t/best-approach-to-add-or-remove-users-to-match-list/14326/2 "2014-01-14T17:35:30Z")

</div>

I have the similar requirement and started working on a role called user management. It is available from [https://galaxy.ansibleworks.com/list#/roles/22](https://galaxy.ansibleworks.com/list#/roles/22) but it is far from complete. As a proof-of-concept it currently deals with user-accounts that should be removed (or locked / disabled) if they no longer exist in a given list.

I’m planing to enhance that role and if you were interested in joining forces, that would be great.
