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.
Ansible Create Windows Local User: win_user Module (Complete Guide) — Video Tutorial
How to create local user accounts on Windows with Ansible win_user module. Set passwords, groups, permissions, and manage user lifecycle with playbook examples.
What You'll Learn
- How to Create a local user on Windows-like systems with Ansible?
- Ansible creates the user account
- Parameters
- Links
- code
- execution
- idempotency
- before execution
- after execution
- Conclusion
Full Tutorial Content
How to Create a local user 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
Ansible creates the user account
> `ansible.windows.win_user` Manages local Windows user accounts
Today we're talking about Ansible module `win_user`.
The full name is `ansible.windows.win_user`, 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 manages local Windows user accounts.
For Linux target use the `user` module instead.
Parameters
- `name` _string_ - user name
- `state` _string_ - present/absent
- `password` _string_ - cleartext password
- `description` _string_ - description of the group
- `groups` _list_ - list of groups to adds or removes
- `update_password` _string_ - always / on_create
- `password_never_expires` _boolean_ - no / yes
- `password_expired` _string_ - yes - change at next login / no
- `account_locked` / account_disabled - no /yes
The only required is "name", which is the user name.
The "state" parameter allows us to create or delete a user, in our use case the default it's already set to "present" to create a user.
The "password" set the password in cleartext. So easily specify what password assign to the user, no hash function are needed.
The "description" parameter allows you to specify a description of the user, it's not mandatory but sometimes is useful.
The "groups" parameter allows you to add or remove the user from this list of groups.
The "update_password" parameter specifies when the module will update the user password. "always" option will update passwords if they differ, "on_create" will only set the password for newly created users.
Let me highlight also some parameters about password expiration "password_never_expires" to sets the password to never expire, or "password_expired" force the user to change the password at the next login.
You could also lock or disable the account using "account_locked" and "account_disabled" parameters.
Links
- [ansible.windows.win_user](https://docs.ansible.com/ansible/latest/collections/ansible/windows/win_user_module.html)
## Playbook
How to create a local user on Windows-like systems with Ansible Playbook.
I'm going to show you how to automate the creation of the "example" user member of the Users group on my Playbook Windows machine.
code
```yaml
---
- name: windows user add
hosts: all
vars:
usr_name: 'example'
usr_password: 'EfY#Qs9*BWy9?'
usr_groups: "Users"
tasks:
- name: create local user
ansible.windows.win_user:
name: "{{ usr_name }}"
password: "{{ usr_password }}"
groups: "{{ usr_groups }}"
update_password: on_create
password_expired: true
```
execution
```bash
ansible-pilot $ ansible-playbook -i virtualmachines/win/inventory wi
About This Tutorial
- Author: Luca Berton
- Difficulty: Beginner
- Read time: 5 min
- Category: troubleshooting
Read the full written article: Ansible Create Windows Local User: win_user Module (Complete Guide)
Related Video Tutorials
- 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 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.
- 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.
- Remove a local group on Windows-like systems - Ansible module win_group — How to automate the removal of a local group "accounting" on Windows-like systems using the Ansible module win_group.
- 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 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.