Create Local Groups on Windows with Ansible Playbooks
By Luca Berton · Published 2024-01-01 · Category: troubleshooting
Learn how to create and manage local groups on Windows systems using Ansible’s win_group module. Follow our detailed Playbook example for automation.

How to Create a local group on Windows-like systems with Ansible?
See also: Remove a local group on Windows-like systems - Ansible module win_group
Ansible creates a local 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
See also: Ansible Change Windows User Password: win_user Module (Examples)
Links
## Playbook How to Create a local group on Windows-like systems with Ansible Playbook. I’m going to show you how to automate the creation of the “example” group on my Playbook Windows machine.
code
---
- name: windows group add
hosts: all
vars:
grp_name: 'accounting'
grp_description: 'accounting group'
tasks:
- name: Create a new group
ansible.windows.win_group:
name: "{{ grp_name }}"
description: "{{ grp_description }}"
state: presentexecution
ansible-pilot $ ansible-playbook -i virtualmachines/win/inventory windows/group_add.yml
PLAY [windows group add] **************************************************************************
TASK [Gathering Facts] ****************************************************************************
ok: [WindowsServer]
TASK [Create a new 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_add.yml
PLAY [windows group add] **************************************************************************
TASK [Gathering Facts] ****************************************************************************
ok: [WindowsServer]
TASK [Create a new 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
Conclusion
Now you know how to create a local group on Windows-like systems with Ansible.
See also: Ansible Create Windows Local User: win_user Module (Complete Guide)
Related Articles
Category: troubleshooting
Watch the video: Create Local Groups on Windows with Ansible Playbooks — Video Tutorial