All HowTo's Ansible & Terraform Automation

Using Ansible to Add a User to a Group

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


  - 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”.

Leave a Reply

Your email address will not be published. Required fields are marked *