Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

What is the cleanest way of doing this? Tried adding the user to the sudo group with the users module but Ansible reports it can't find the sudo group.

share|improve this question
up vote 8 down vote accepted

Instead of

- name: create a new user
    user: name=user
          state=present
          groups="group1, group2"
          password={{ password }}
          comment="Comment"

I did

- name: create a new user
    user: name=user
          state=present
          group=primary-group
          groups="sudo"
          password={{ password }}
          comment="Comment"

And the user was added to the sudo group.

share|improve this answer
2  
groups="www, sudo" msg: Group sudo does not exist, on ubuntu 14 – holms Jul 17 '14 at 12:59
2  
You probably want the 'wheel' group – Adam Nelson Nov 14 '14 at 13:41
1  
Setting a password should be a last resort - better to use keys only. – Adam Nelson Nov 14 '14 at 13:41
    
Is the intention that once this task is run, all other playbook tasks are executed as 'user' user? – emeraldjava Jan 22 at 16:03
- name: Create Deploy user
  user: name={{ deploy }} comment="Deploy User" groups="sudo,admin,{{ deploy }}"
  sudo: yes

Be careful of spaces in your groups list... You get the "group does not exist" if you have them.

share|improve this answer

groups="admin" will create user add in admin groups

share|improve this answer
3  
in which os? "Group admin does not exist" on ubuntu 1404 – holms Jul 17 '14 at 13:04

In ansible v2.1.0, you can add "wheel" to groups in playbook on Linux, like this

- name: Create a new user
  user: name=admin groups=wheel
  become: yes
  become_method: sudo
share|improve this answer

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.