All Linux HowTo's

Add a New or Existing user to Multiple Groups using Ansible

Share This:

There are several popular search results for this answer but they all skip the important part – and are incorrect as a result.

---
- hosts: all

  sudo: yes

  tasks:

  - user: name=myuser comment="My User" groups=wheel,group1,group2 append=yes

This is where they are (and likely you are) going wrong. The “groups” option and the “append=yes” option. “groups” has an “s” in it. If you’re having trouble adding a new or existing user to multiple groups then this is likely the solution.