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 Remove Windows User: win_user Module state=absent (Examples) — Video Tutorial

How to remove local Windows user accounts with Ansible win_user module. Delete users, remove profiles, and manage Windows accounts across multiple servers.

Watch Video

Watch "Ansible Remove Windows User: win_user Module state=absent (Examples)" on YouTube

What You'll Learn

Full Tutorial Content

How to Remove 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 remove local 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 The only required is "name", which is the user name. The "state" parameter allows us to create or delete a user. For our use case, we need to use the "absent" option. ## Playbook How to Remove a local user on Windows-like systems with Ansible Playbook. I'm going to show you how to automate the deletion of the "example" user on my Playbook Windows machine. code ```yaml --- - name: windows user remove hosts: all vars: usr_name: 'example' tasks: - name: delete local user ansible.windows.win_user: name: "{{ usr_name }}" state: absent ``` execution ```bash ansible-pilot $ ansible-playbook -i virtualmachines/win/inventory windows/user_remove.yml PLAY [windows user remove] ************************************************************************ TASK [Gathering Facts] **************************************************************************** ok: [WindowsServer] TASK [delete local user] ************************************************************************** changed: [WindowsServer] PLAY RECAP **************************************************************************************** WindowsServer : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 ansible-pilot $ ``` idempotency ```bash ansible-pilot $ ansible-playbook -i virtualmachines/win/inventory windows/user_remove.yml PLAY [windows user remove] ************************************************************************ TASK [Gathering Facts] **************************************************************************** ok: [WindowsServer] TASK [delete local user] ************************************************************************** ok: [WindowsServer] PLAY RECAP **************************************************************************************** WindowsServer : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 ansible-pilot $ ``` before execution ![win_user before execution](/articles/ansible_module_win_user_remove1.jpg) after execution ![win_user after execution](/articles/ansible_module_win_user_remove2.jpg) [code with ❤️ in GitHub](https://github.com/lucab85/ansible-pilot/) Conclu

About This Tutorial

Read the full written article: Ansible Remove Windows User: win_user Module state=absent (Examples)

Topics Covered

Related Video Tutorials