Ansible Pilot

Create a group in Linux - Ansible module group

Access the Complete Video Course and Learn Quick Ansible by 200+ Practical Lessons

How to create the "example" group or verify that is present on your target Linux system or macOS.

How to create a group in Linux with Ansible?

I’m going to show you a live demo with some simple Ansible code. I’m Luca Berton and welcome to today’s episode of Ansible Pilot.

Ansible creates a group

Today we’re talking about the Ansible module group. The full name is, which means that is part of the collection of modules “builtin” with ansible and shipped with it. It’s a module pretty stable and out for years. It adds or removes groups. It supports a huge variety of Linux distributions and macOS. It relies on three Linux commands: groupadd, groupdel and groupmod. For Windows, use the module instead.


This module has some parameters to perform some tasks. The only required is “name”, which is the group name. The “state” parameter allows us to create or delete a group, in our use case the default it’s already set to “present” to create a group. The “system” parameter allows for the creation of a system group, default it’s not. You could specify the “GID”, the group identifier, in using the “gid” parameter. The “local” parameter allows using the “local” command alternatives on platforms that implement it if you have a central authentication system.


Let’s jump in a real-life Ansible Playbook to create a group.


- name: group module demo
  hosts: all
  become: true
    mygroup: "example"
    - name: create group
        name: "{{ mygroup }}"
        state: present


$ ansible-playbook -i demo/inventory group/create.yml
PLAY [group module demo] **************************************************************************
TASK [Gathering Facts] ****************************************************************************
ok: []
TASK [create group] *******************************************************************************
changed: []
PLAY RECAP ****************************************************************************************           : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0


$ ssh [email protected]
$ sudo su
# getent group | grep example


code with ❤️ in GitHub


Now you know how to create a group in Linux with Ansible. Subscribe to the YouTube channel, Medium, Website and Twitter to not miss the next episode of the Ansible Pilot.


Learn the Ansible automation technology with some real-life examples in my

My book Ansible By Examples: 100+ Automation Examples For Linux and Windows System Administrator and DevOps

Access the Complete Book and Learn Quick Ansible by 200+ Examples

Want to keep this project going? Please donate

Access the Complete Video Course and Learn Quick Ansible by 200+ Practical Lessons
Follow me

Subscribe not to miss any new releases

October 22, 2021

FREE Top 10 Best Practices

Top 10 Best Practices of Ansible Automation: save time, reduce errors and stress