user creation with sudo permissions

27 views
Skip to first unread message

Pedro Ferro

unread,
Feb 13, 2017, 1:34:41 PM2/13/17
to Ansible Project
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

Johannes Kastl

unread,
Feb 13, 2017, 3:49:34 PM2/13/17
to ansible...@googlegroups.com
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

signature.asc

Pedro Ferro

unread,
Feb 14, 2017, 4:22:22 AM2/14/17
to Ansible Project
thanks for the help, Johannes.
Reply all
Reply to author
Forward
0 new messages