Create a local group on Windows-like systems - Ansible module win_group
How to automate the creation of the "accounting" local group on Windows-like systems with Ansible Playbook with win_group module.


How to Create a local group on Windows-like systems with Ansible?
I’m going to show you a live demo with some simple Ansible code. I’m Luca Berton and welcome to today’s episode of Ansible Pilot.
Ansible creates a local group on Windows-like systems
ansible.windows.win_group
- Add or remove groups
Today we’re talking about the 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
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 “description” parameter allows you to specify a description of the group, it’s not mandatory but sometimes is useful.
Links
The Best Resources For Ansible
Video Course
Printed Book
eBooks
- Ansible by Examples: 200+ Automation Examples For Linux and Windows System Administrator and DevOps
- Ansible For Windows By Examples: 50+ Automation Examples For Windows System Administrator And DevOps
- Ansible For Linux by Examples: 100+ Automation Examples For Linux System Administrator and DevOps
- Ansible Linux Filesystem By Examples: 40+ Automation Examples on Linux File and Directory Operation for Modern IT Infrastructure
- Ansible For Containers and Kubernetes By Examples: 20+ Automation Examples To Automate Containers, Kubernetes and OpenShift
- Ansible For Security by Examples: 100+ Automation Examples to Automate Security and Verify Compliance for IT Modern Infrastructure
- Ansible Tips and Tricks: 10+ Ansible Examples to Save Time and Automate More Tasks
- Ansible Linux Users & Groups By Examples: 20+ Automation Examples on Linux Users and Groups Operation for Modern IT Infrastructure
- Ansible For PostgreSQL by Examples: 10+ Examples To Automate Your PostgreSQL database
- Ansible For Amazon Web Services AWS By Examples: 10+ Examples To Automate Your AWS Modern Infrastructure
- Ansible Automation Platform By Example: A step-by-step guide for the most common user scenarios
demo
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 demo 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: present
execution
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
Recap
Now you know how to create a local group on Windows-like systems with Ansible. Subscribe to the YouTube channel, Medium, Website, Twitter, and Substack to not miss the next episode of the Ansible Pilot.
Academy
Learn the Ansible automation technology with some real-life examples in my
My book Ansible By Examples: 200+ Automation Examples For Linux and Windows System Administrator and DevOps
Donate
Want to keep this project going? Please donate