# advanced user managent

**URL:** <https://forum.ansible.com/t/advanced-user-managent/12773>\
**Category:** Ansible Project\
**Created:** [May 6, 2013, 1:42pm UTC](https://forum.ansible.com/t/advanced-user-managent/12773 "2013-05-06T13:42:36Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hudec\_Peter](https://avatars.discourse-cdn.com/v4/letter/h/a87d85/32.png) [@Hudec\_Peter](https://forum.ansible.com/u/Hudec_Peter)\
**Post date:** [May 6, 2013, 1:42pm UTC](https://forum.ansible.com/t/advanced-user-managent/12773/1 "2013-05-06T13:42:36Z")

</div>

Hi all,

I'm migrating form puppet. The last playbook/manifest which is missing is  
the user management.

On the puppet I wroute module and some libs an it worked like this

I habe list of pavl users in some array  
users\_available: user01, user02, user03, user04

For each server I have list of enabled users, this could be done by  
host\_vars in ansible  
users\_enabled: user01, user03

If you add the user to the "users\_enabled", the user is created. So far so  
good.

And now the tricky part. If you remove the user from the user\_enabled, the  
user is removed, so the ansible script should be able to check  
- If the user in "users\_enabled" and do not exists, create it  
- if the user in "users\_avaiable" - "users\_enabled" and exists, remote it

Please could anybody help me to solve this tricky problem? I' managing  
couple of server, where no all users have access to all servers.

So I need to do the list difference.

&nbsp;&nbsp;best regards  
&nbsp;&nbsp;&nbsp;&nbsp;Peter Hudec

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [May 6, 2013, 7:49pm UTC](https://forum.ansible.com/t/advanced-user-managent/12773/2 "2013-05-06T19:49:03Z")

</div>

The basic idea here would be to use “with\_items”…

tasks:

- action: user name={{ item }} state=present  
with\_items: some\_list\_of\_users

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [May 6, 2013, 7:49pm UTC](https://forum.ansible.com/t/advanced-user-managent/12773/3 "2013-05-06T19:49:33Z")

</div>

BTW, note I’m using 1.2 syntax, if you are still on 1.1:

with\_items: ${some\_list\_of\_users}

---

<div class="post-metadata">

**Author:** ![Hudec\_Peter](https://avatars.discourse-cdn.com/v4/letter/h/a87d85/32.png) [@Hudec\_Peter](https://forum.ansible.com/u/Hudec_Peter)\
**Post date:** [May 6, 2013, 7:56pm UTC](https://forum.ansible.com/t/advanced-user-managent/12773/4 "2013-05-06T19:56:31Z")

</div>

Hi Michael,

The snippet is about state=present, but there is no answer for the send part of my question, aka deleting users.

I solved it few mins ago as

action: user name={{ item }} state=present  
with\_items: users\_available  
when: “item in users\_enabled”  
tags: test

- action: user name={{ item }} state=absent force=yes remove=yes  
with\_items: users\_available  
when: “not item in users\_enabled”  
tags: test

But the params force and remove seems to be broken. The user directory is not removed ;(

Peter

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [May 6, 2013, 8:24pm UTC](https://forum.ansible.com/t/advanced-user-managent/12773/5 "2013-05-06T20:24:12Z")

</div>

Run in verbose mode please and show me your output.

---

<div class="post-metadata">

**Author:** ![Hudec\_Peter](https://avatars.discourse-cdn.com/v4/letter/h/a87d85/32.png) [@Hudec\_Peter](https://forum.ansible.com/u/Hudec_Peter)\
**Post date:** [May 7, 2013, 7:28am UTC](https://forum.ansible.com/t/advanced-user-managent/12773/6 "2013-05-07T07:28:15Z")

</div>

Hi Micheal,

This solution is working.  
users\_availavle: phudec,lgelo,jcunik,…  
users\_enabeld: phudec,lgelo

GATHERING FACTS
