AnsiblePilot — Master Ansible Automation

AnsiblePilot is the leading resource for learning Ansible automation, DevOps, and infrastructure as code. Browse over 1,400 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 8 Ansible books published by Apress and Leanpub including "Ansible for VMware by Examples" and "Ansible for Kubernetes by Example", 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 Manage Groups: Create, Delete & Modify with group Module — Video Tutorial

How to manage Linux groups with Ansible group module. Create groups, delete groups, set GIDs, manage system groups, and assign users to groups.

Watch on YouTube · Read the written article

Tutorial summary

What you'll learn

  • How to delete a group in Linux with Ansible?
  • Ansible deletes a group account
  • Parameters
  • code
  • execution
  • verification
  • Conclusion
  • Remove a Group
  • Remove Multiple Groups
  • Safe Removal (Check Members First)
How to delete a group in Linux with Ansible? Ansible deletes a group account - `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 - 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 set to "absent" to delete a group. 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 delete a group. code - group_delete.yml ```yaml --- - name: group module Playbook hosts: all become: true vars: mygroup: "example" tasks: - name: delete group ansible.builtin.group: name: "{{ mygroup }}" state: absent ``` execution output ```bash $ ansible-playbook -i Playbook/inventory group/delete.yml PLAY [group module Playbook] ************************************************************************** TASK [Gathering Facts] **************************************************************************** ok: [demo.example.com] TASK [delete 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 [devops@demo ~]$ sudo su [root@demo devops]# getent group | grep example [root@demo devops]# getent group root:x:0: bin:x:1: daemon:x:2: sys:x:3: adm:x:4: tty:x:5: disk:x:6: lp:x:7: mem:x:8: kmem:x:9: wheel:x:10: cdrom:x:11: mail:x:12: man:x:15: dialout:x:18: floppy:x:19: games:x:20: tape:x:33: video:x:39: ftp:x:50: lock:x:54: audio:x:63: users:x:100:devops nobody:x:65534: dbus:x:81: utmp:x:22: utempter:x:35: input:x:999: kvm:x:36: render:x:998: systemd-journal:x:190: systemd-coredump:x:997: systemd-resolve:x:193: tss:x:59: polkitd:x:996: ssh_keys:x:995: unbound:x:994: sssd:x:993: chrony:x:992: sshd:x:74: vagrant:x:1000: vboxsf:x:991: slocate:x:21: ``` [code with ❤️ in GitHub](https://github.com/lucab85/ansible-pilot/) Conclusion Now you know how to delete a group in Linux with Ansible. Remove a Group ```yaml - name: Remove the old-project group ansible.buil

About this tutorial

  • Author: Luca Berton
  • Difficulty: Beginner
  • Read time: 7 min
  • Category: troubleshooting

Topics covered

Related video tutorials