# add user to group but don't add user

**URL:** <https://forum.ansible.com/t/add-user-to-group-but-dont-add-user/13410>\
**Category:** Ansible Project\
**Created:** [September 3, 2013, 7:51am UTC](https://forum.ansible.com/t/add-user-to-group-but-dont-add-user/13410 "2013-09-03T07:51:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![seb.stark](https://avatars.discourse-cdn.com/v4/letter/s/e9c0ed/32.png) [@seb.stark](https://forum.ansible.com/u/seb.stark)\
**Post date:** [September 3, 2013, 7:51am UTC](https://forum.ansible.com/t/add-user-to-group-but-dont-add-user/13410/1 "2013-09-03T07:51:24Z")

</div>

Hi,

I would like to add a user to a group like that:

- name: Set main user  
action: user name={{ main\_user }} groups={{ local\_admin\_group }} append=yes state=present  
when: main\_user is defined  
tags:
- users

However, it is possible that at the point this runs the user is not available (e. g. sssd not running, LDAP server not available, …) which leads to the user being added to /etc/passwd.

How can I prevent the user from being created locally by the user module? I feel this is something that could be easily added to the module, but maybe there is another way already.

Sebastian

---

<div class="post-metadata">

**Author:** ![seb.stark](https://avatars.discourse-cdn.com/v4/letter/s/e9c0ed/32.png) [@seb.stark](https://forum.ansible.com/u/seb.stark)\
**Post date:** [September 3, 2013, 7:54am UTC](https://forum.ansible.com/t/add-user-to-group-but-dont-add-user/13410/2 "2013-09-03T07:54:26Z")

</div>

Just wanted to add: the “when: main\_user is defined” has nothing to do with my question, it’s there for another reason.

---

<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:** [September 3, 2013, 2:04pm UTC](https://forum.ansible.com/t/add-user-to-group-but-dont-add-user/13410/3 "2013-09-03T14:04:22Z")

</div>

Yeah, this isn’t something it can do now, but it would be easy to add.

I would suggest a syntax of state=group\_only

which might make certain options mutually incompatible with it.

Something you might want to work on perhaps?

If not, please open a feature request in github so we don’t lose track of the idea.

Thanks!

---

<div class="post-metadata">

**Author:** ![seb.stark](https://avatars.discourse-cdn.com/v4/letter/s/e9c0ed/32.png) [@seb.stark](https://forum.ansible.com/u/seb.stark)\
**Post date:** [September 3, 2013, 2:42pm UTC](https://forum.ansible.com/t/add-user-to-group-but-dont-add-user/13410/4 "2013-09-03T14:42:05Z")

</div>

I’ll give it a try.
