AnsiblePilot — Master Ansible Automation
AnsiblePilot is the leading resource for learning Ansible automation, DevOps, and infrastructure as code. Browse over 1,100 tutorials covering Ansible modules, playbooks, roles, collections, and real-world examples. Whether you are a beginner or an experienced engineer, our step-by-step guides help you automate Linux, Windows, cloud, containers, and network infrastructure.
Popular Topics
About Luca Berton
Luca Berton is an Ansible automation expert, author of "Ansible for VMware by Examples" and "Ansible for Kubernetes by Example" published by Apress, and creator of the Ansible Pilot YouTube channel. He shares practical automation knowledge through tutorials, books, and video courses to help IT professionals and DevOps engineers master infrastructure automation.
Ansible group Module: Create & Manage Linux Groups (ansible.builtin.group) — Video Tutorial
How to create and manage Linux groups with Ansible group module (ansible.builtin.group). Add groups, set GID, manage system groups. Practical YAML playbook examples.
What You'll Learn
- How to create a group in Linux with Ansible?
- Ansible creates a group
- Parameters
- code
- execution
- verification
- Conclusion
- Create Groups
- Basic group
- With specific GID
Full Tutorial Content
How to create a group in Linux with Ansible?
I'm going to show you a live Playbook with some simple Ansible code.
I'm Luca Berton and welcome to today's episode of Ansible Pilot.
Ansible creates a group
> `ansible.builtin.group` Add or remove groups
Today we're talking about the Ansible module group.
The full name is `ansible.builtin.group`, 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 `ansible.windows.win_group` module instead.
Parameters
- `name` string - group name
- `state` string - present/absent
- `system` boolean - yes/no
- `gid` integer - GID to set for the group
- `local` string - "local" command alternatives
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.
## Playbook
Let's jump in a real-life Ansible Playbook to create a group.
code
- create_group.yml
```yaml
---
- name: group module Playbook
hosts: all
become: true
vars:
mygroup: "example"
tasks:
- name: create group
ansible.builtin.group:
name: "{{ mygroup }}"
state: present
```
execution
```bash
$ ansible-playbook group/create.yml
PLAY [group module Playbook] **************************************************************************
TASK [Gathering Facts] ****************************************************************************
ok: [demo.example.com]
TASK [create group] *******************************************************************************
changed: [demo.example.com]
PLAY RECAP ****************************************************************************************
demo.example.com : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
```
verification
```bash
$ ssh devops@demo.example.com
$ sudo su
getent group | grep example
example:x:1001:
```
[code with ❤️ in GitHub](https://github.com/lucab85/ansible-pilot/tree/master/create%20file)
Conclusion
Now you know how to create a group in Linux with Ansible.
Create Groups
Basic group
```yaml
- name: Create developers group
ansible.builtin.group:
name: developers
state: present
become: true
```
With specific GID
```yaml
- name: Create group with GID
ansible.builtin.group:
name: appteam
gid: 1500
state:
About This Tutorial
- Author: Luca Berton
- Difficulty: Beginner
- Read time: 6 min
- Category: troubleshooting
Read the full written article: Ansible group Module: Create & Manage Linux Groups (ansible.builtin.group)
Related Video Tutorials
- Ansible Manage Groups: Create, Delete & Modify with group Module — How to manage Linux groups with Ansible group module. Create groups, delete groups, set GIDs, manage system groups, and assign users to groups.
- Ansible Create User Account: user Module Complete Guide — How to create user accounts with Ansible user module. Set passwords, SSH keys, groups, shells, home directories, and manage users with examples.
- Ansible Password Expiration: Manage User Account Aging & Policies — How to manage password expiration with Ansible user module. Set expiry dates, maximum age, warning periods, and enforce password rotation policies.
- Add Secondary Groups to Linux Users with Ansible Playbook — Learn how to add secondary groups to Linux users with an Ansible playbook. This step-by-step guide includes YAML configuration and execution details.
- Change the User Primary Group on Linux with Ansible — Learn how to use Ansible to change a user's primary group on Linux systems with the user module. Streamline user management and ensure consistent group assignments across your infrastructure.
- ansible.builtin.user: Change User Password with Ansible (Secure Guide) — How to change user passwords with Ansible user module. Hash passwords securely, use Vault for credentials, manage password rotation across servers.