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 Change Windows User Password: win_user Module (Examples) — Video Tutorial

How to change local Windows user passwords with Ansible win_user module. Reset passwords, set expiry policies, and manage credentials across Windows servers.

Watch Video

Watch "Ansible Change Windows User Password: win_user Module (Examples)" on YouTube

What You'll Learn

Full Tutorial Content

How to change user passwords on Windows-like systems with Ansible? Password change is a mundane task that every System Administrator needs to perform regularly for your user base. Using Ansible you could simplify your workflow and maintain consistent your IT infrastructure fleet. 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 changes local user password > `ansible.windows.win_user` Manages local Windows user accounts Today we're talking about the 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_ - clear text password - `update_password` _string_ - `always` / `on_create` 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 clear text. So easily specify what password assign to the user, no hash function is needed. 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. Links - [ansible.windows.win_user](https://docs.ansible.com/ansible/latest/collections/ansible/windows/win_user_module.html) - [Lastpass password generator](https://www.lastpass.com/it/features/password-generator) ## Playbook Change user password on Windows-like systems with Ansible Playbook. I'm going to show you how to automate the password of local user "example" with an autogenerated one and verify on the Windows side with a successful login. code ```yaml --- - name: windows change password hosts: all vars: usr_name: 'example' usr_password: 'SMJAo$%8AzU6' tasks: - name: change password ansible.windows.win_user: name: "{{ usr_name }}" password: "{{ usr_password }}" ``` execution ```bash ansible-pilot $ ansible-playbook -i virtualmachines/win/inventory windows/user_changepassword.yml PLAY [windows change password] ******************************************************************** TASK [Gathering Facts] **************************************************************************** ok: [WindowsServer] TASK [change password] **************************************************************************** changed: [WindowsServer] PLAY RECAP **************************************************************************************** WindowsServer : ok=2 changed=1 unreachable=0 failed=0 skipped=0

About This Tutorial

Read the full written article: Ansible Change Windows User Password: win_user Module (Examples)

Topics Covered

Related Video Tutorials