This is a short example article showing how you can add an existing use to an existing group. Read the other Ansible articles on this blog site for more information about how YML files are formatted.
---
- hosts: all
sudo: yes
tasks:
- user:
name: myusername
shell: /bin/bash
groups: wheel,group1,group2
append: yes
Note the “append: yes” option which will keep the users existing group membership untouched while adding only the new group memberships as “wheel, group1 and group2”.