Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I can't add a user to multiple groups, I keep getting msg: this module requires key=value arguments.

This is the piece of code I'm trying:

- name: make a new user
  user: name=user
        groups="group1", "group2", "group3"

The documentation says: Groups= Puts the user in this comma-delimited list of groups. When set to the empty string ('groups='), the user is removed from all groups except the primary group.

I have tried with "group", 'group', and without colons and still get the same error.

share|improve this question

The correct syntax is:

- name: make a new user
  user: name=user
        groups="group1, group2, group3"
share|improve this answer

The above answers are incorrect. The right way to define a variable:

groups: group1,group2 

Then to use:

action: user groups={{user.groups}}
share|improve this answer
there is no set order for displaying answers.. "above" can mean one thing to you and a different thing to someone else. Or even a different thing to you, tomorrow. – dan3 Mar 22 '15 at 8:19
@dan3 thanks for clarifying ;p – Florian Heigl Sep 9 '15 at 13:20

I get Group " group2" does not exist. (But without the quotes, thats to show the extra space).

Correct way is

groups={{ group }},{{ sudo_group }}
share|improve this answer
As for the response that "group2 doesn't exist", a group has to exist before you add a user to the group. Adding a user, and specifying the user is a member of a group that doesn't exist, does not create the group. When adding users and groups, create the groups first, then add your users. (The one exception is the group that is created at the same time as the user, on systems that use group-per-user (most Linux's)). – Andrew Edelstein Aug 11 '15 at 21:36

There are two issues with the code you posted:

  1. To pass multiple values to groups, use comma-separated values with no spaces in between: groups: group1,group2
  2. In YAML, when you put each key on its own line, swap the = for :

Here's an example of working code:

- name: make a new user
    name: johnsmith
    state: present
    groups: group1,group2
    comment: "comment"
    append: no # If yes, will only add groups, not set them to just the list in groups.
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.