add user to group but don't add user

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

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

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!

I’ll give it a try.