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