Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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
        state=present
        groups="group1", "group2", "group3"
        comment="comment"

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.

http://docs.ansible.com/user_module.html

share|improve this question
add comment

3 Answers

The correct syntax is:

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

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
add comment

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
add comment

Your Answer

 
discard

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.