user creation with sudo permissions

Hi,

I’m not an IT guy and I’m trying to start using Ansible, so you have to excuse basic questions like this one.

What is the ansible equivalent for this:

sudo adduser admin
sudo adduser admin sudo

Thanks in advance,
Pedro

To escalate your privileges (i.e. use sudo) you use the become
directive in ansible:
https://docs.ansible.com/ansible/become.html

To add, modify or delete users use the user module:
http://docs.ansible.com/ansible/user_module.html

So, this would end up in a task like this:

- name: Add user foobar
  user:
    name: foobar
    groups: sudo
    append: yes
  become: yes
  become_method:sudo

(Untested)

Of course, you need to run ansible as a user that is allowed to add
users. Root or another user, that is allowed to run sudo...

Johannes

thanks for the help, Johannes.

segunda-feira, 13 de Fevereiro de 2017 às 20:49:34 UTC, Johannes Kastl escreveu: