How do I add sudo permissions to a user created with Ansible?

Solution 1:

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.

Solution 2:

- 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.

Tags:

Ansible