Remove a local group on Windows-like systems - Ansible module win_group
By Luca Berton · Published 2022-03-21 · Category: troubleshooting
How to automate the removal of a local group "accounting" on Windows-like systems using the Ansible module win_group.

How to Remove a local group on Windows-like systems with Ansible?
Note: Be very careful about typing the right group name because the delete operation is irreversible!
See also: Create Local Groups on Windows with Ansible Playbooks
Ansible Remove a group on Windows-like systems
ansible.windows.win_group- Add or remove groups
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
## Playbook
How to remove a local group on Windows-like systems with Ansible Playbook.
code
---
- name: windows group remove
hosts: all
vars:
grp_name: 'accounting'
tasks:
- name: remove group
ansible.windows.win_group:
name: "{{ grp_name }}"
state: absentexecution
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
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
ansible-pilot $before execution
after execution
See also: Ansible Change Windows User Password: win_user Module (Examples)
Conclusion
Now you know how to remove a local group on Windows-like systems with Ansible.
Related Articles
Category: troubleshooting
Watch the video: Remove a local group on Windows-like systems - Ansible module win_group — Video Tutorial