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.
Remove a local group on Windows-like systems - Ansible module win_group — Video Tutorial
How to automate the removal of a local group "accounting" on Windows-like systems using the Ansible module win_group.
What You'll Learn
- How to Remove a local group on Windows-like systems with Ansible?
- Ansible Remove a group on Windows-like systems
- Parameters
- code
- execution
- idempotency
- before execution
- after execution
- Conclusion
- Related Articles
Full Tutorial Content
How to Remove a local group on Windows-like systems 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.
Note: Be very careful about typing the right group name because the delete operation is irreversible!
Ansible Remove a group on Windows-like systems
- `ansible.windows.win_group`
- Add or remove groups
Today we're talking about Ansible module `win_group`.
The full name is `ansible.windows.win_group `, which means that is part of the collection of modules specialized to interact with Windows target host.
It's a module pretty stable and out for years.
It works in Windows and Windows Server operating systems.
It adds and removes local groups.
For Linux target use the `group` module instead.
Parameters
- name _string_ - group name
- state _string_ - present/absent
- description _string_ - description of the group
The only required is "name", which is the group name.
The "state" parameter allows us to remove or delete a group, in our use case we need to specify "absent" to remove a group.
The "description" parameter allows you to specify a description of the group, it's not necessary in this use case.
## Playbook
How to remove a local group on Windows-like systems with Ansible Playbook.
I'm going to show you how to automate the deletion of the "accounting" group on my Playbook Windows machine.
code
```yaml
---
- name: windows group remove
hosts: all
vars:
grp_name: 'accounting'
tasks:
- name: remove group
ansible.windows.win_group:
name: "{{ grp_name }}"
state: absent
```
execution
```bash
ansible-pilot $ ansible-playbook -i virtualmachines/win/inventory windows/group_remove.yml
PLAY [windows group remove] ***********************************************************************
TASK [Gathering Facts] ****************************************************************************
ok: [WindowsServer]
TASK [remove group] *******************************************************************************
changed: [WindowsServer]
PLAY RECAP ****************************************************************************************
WindowsServer : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
ansible-pilot $
```
idempotency
```bash
ansible-pilot $ ansible-playbook -i virtualmachines/win/inventory windows/group_remove.yml
PLAY [windows group remove] ***********************************************************************
TASK [Gathering Facts] ****************************************************************************
ok: [WindowsServer]
TASK [remove group] *******************************************************************************
ok: [WindowsServer]
PLAY RECAP ****************************************************************************************
WindowsServer : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
a
About This Tutorial
- Author: Luca Berton
- Difficulty: Beginner
- Read time: 2 min
- Category: troubleshooting
Read the full written article: Remove a local group on Windows-like systems - Ansible module win_group
Related Video Tutorials
- Create Local Groups on Windows with Ansible Playbooks — Learn how to create and manage local groups on Windows systems using Ansible’s win_group module. Follow our detailed Playbook example for automation.
- Ansible Change Windows User Password: win_user Module (Examples) — How to change local Windows user passwords with Ansible win_user module. Reset passwords, set expiry policies, and manage credentials across Windows servers.
- Ansible group Module: Create & Manage Linux Groups (ansible.builtin.group) — 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.
- Ansible Create Windows Local User: win_user Module (Complete Guide) — How to create local user accounts on Windows with Ansible win_user module. Set passwords, groups, permissions, and manage user lifecycle with playbook examples.
- 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 Remove Windows User: win_user Module state=absent (Examples) — How to remove local Windows user accounts with Ansible win_user module. Delete users, remove profiles, and manage Windows accounts across multiple servers.