If you are not familiar with modules, check out Ansible - Getting Started with Modules.
The user module is similar to the useradd and usermod commands. The user module is used to create or modify a users account on a managed node (e.g. target system).
If the users account does not exist, the users account will be created. If the users account already exists, the users account will be modified.
Before using this module, you should probably use the group module to create the group if the group does not yet exist on the managed node.
There are two group parameters:
In this example, John Doe's primary group will be set to wheel.
- name: john.doe primary group is 'wheel'
user:
name: john.doe
group: wheel
Let's say John Doe's primary group is 'john.doe' and you want to add John Doe to group2 and group3. In this scenario, you would use groups (with an "s") and append.
- name: add john.doe to 'group2' and 'group3'
user:
name: john.doe
groups: group2,group3