• Categories
    Category
  • Categories
    Category
  • News
  • Tutorials
  • Forums
  • Tags
  • Users
Tutorial Comments FAQ Related Articles

How to add or remove Windows user by Ansible playbook

  • 00:44 lsb_release -a
  • 01:18 apt list -a python3-pip
  • 01:38 pip list | grep pywinrm
  • 01:57 vi /etc/ansible/hosts
  • 05:14 ansible-playbook useradd.yml --syntax-check
  • 06:39 vi removeuser.yml
  • 08:40 ansible-playbook removeuser.yml
6734

To Add or Remove Windows user by Ansible playbook

Introduction:

Ansible is an IT automation tool used to manage various configurations of both Unix-like and Windows-based systems. The win_user module handles local Windows accounts.

Master Server Requirements:

ansible

python3-pip

pywinrm (python package)

Windows Requirements:

powershell 3+

Dot net 4

Installation Procedure:

Step 1: Check the OS version by using the following command

root@linuxhelp:~# lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 21.04
Release:	21.04
Codename:	hirsute

Step 2: Check the availability of Ansible package

root@linuxhelp:~# apt list -a ansible
Listing... Done
ansible/hirsute,hirsute,now 4.8.0-1ppa~hirsute all [installed]
ansible/hirsute,hirsute 2.10.7-1 all

Step 3: Check the availability of python3-pip package

root@linuxhelp:~# apt list -a python3
Listing... Done
python3/hirsute,now 3.9.4-1 amd64 [installed,automatic]

Step 4: Check the availability of python package pywinrm

root@linuxhelp:~# pip list | grep pywinrm
pywinrm                0.4.2

Step 5: Create inventory for Windows node system

root@linuxhelp:~# vi /etc/ansible/hosts 

[windows]
192.168.6.104

[windows:vars]
ansible_user=Admin
ansible_password=Admin@123
ansible_port=5986
ansible_connection=winrm
ansible_winrm_server_cert_validation=ignore

Step 6: Create playbook for Creating Windows user

root@linuxhelp:~# vi useradd.yml
- hosts: windows
  gather_facts: true
  tasks:
  - name: Creating user "ansibleuser"
    win_user:
     name: ansibleuser
     password: password
     state: present
     groups:
       - Users

Step 7: Check the syntax of the useradd.yml ansible playbook by using the following command

root@linuxhelp:~# ansible-playbook useradd.yml --syntax-check

playbook: useradd.yml

Step 8: Run the useradd.yml playbook by using the following command

root@linuxhelp:~# ansible-playbook useradd.yml 

PLAY [windows] **************************************************************************************************

TASK [Gathering Facts] ******************************************************************************************
ok: [192.168.6.104]

TASK [Creating user "ansibleuser"] ******************************************************************************
changed: [192.168.6.104]

PLAY RECAP *************************************************************************************************

192.168.6.104              : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0 

Step 9: Windows user Created by Ansible Snap 1

Step 10: Create playbook for removing Windows user

root@linuxhelp:~# vi removeuser.yml
- hosts: windows
  gather_facts: true
  tasks:
  - name: Removing user "ansibleuser"
    win_user:
     name: ansibleuser
     state: absent

Step 11: Check the syntax of the removeuser.yml ansible playbook by using the following command

root@linuxhelp:~# ansible-playbook removeuser.yml --syntax-check

playbook: removeuser.yml

Step 12: Run the removeuser.yml playbook by using the following command

root@linuxhelp:~# ansible-playbook removeuser.yml 

PLAY [windows] **************************************************************************************************

TASK [Gathering Facts] ******************************************************************************************
ok: [192.168.6.104]

TASK [Removing user "ansibleuser"] ******************************************************************************
changed: [192.168.6.104]

PLAY RECAP ******************************************************************************************************
192.168.6.104              : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

Step 13: Created Windows user has been removed Snap 2

With this adding/removing of users for windows comes to end

Tags:
iqbal
Author: 

Comments ( 0 )

No comments available

Add a comment

Frequently asked questions ( 5 )

Q

What is win_user?

A

win_user is a module that is maintained by the Ansible Core for managing local Windows user accounts.

Q

How to lock an account?

A

Use "account_locked: yes" to lock any account.

Q

How to define the custom Home Directory of a user?

A

Use home_directory: path" to define custom Home Directory.

Q

How to Change the Password of a user?

A

Use "update_password: password" to Change the Password of a user.

Q

How to remove a User?

A

Use "state: absent" to remove a user.

Related Tutorials in How to add or remove Windows user by Ansible playbook

Related Tutorials in How to add or remove Windows user by Ansible playbook

How to install Windows 10 VM on Proxmox VE
How to install Windows 10 VM on Proxmox VE
Feb 24, 2018
How to Create Ansible Playbook to Install Apache Server
How to Create Ansible Playbook to Install Apache Server
May 12, 2021
How to Install Mailcatcher in Windows 10
How to Install Mailcatcher in Windows 10
Aug 10, 2019
How to set permissions to the files by using Ansible playbook
How to set permissions to the files by using Ansible playbook
Nov 12, 2021
User Management Command in Linux with Examples
User Management Command in Linux with Examples
Mar 22, 2016
How to install and configure Ansible on OpenSUSE leap 15.0
How to install and configure Ansible on OpenSUSE leap 15.0
Nov 22, 2018
How to install an application on Windows by using Ansible playbook
How to install an application on Windows by using Ansible playbook
Nov 10, 2021
How to configure Thunderbird to connect to your Zimbra mailbox
How to configure Thunderbird to connect to your Zimbra mailbox
Feb 26, 2019

Related Forums in How to add or remove Windows user by Ansible playbook

Related Forums in How to add or remove Windows user by Ansible playbook

Net-SNMP
ryder class=
The SNMP Service encountered an error while accessing the registry key SYSTEM\CurrentControlSet\Services\SNMP\Parameters\TrapConfiguration.
Dec 9, 2019
Proxmox
xavier class=
Dual Boot : Windows 7 and Proxmox
Jan 23, 2018
Wifi
matthew class=
The settings saved on this computer for the network do not match the requirements of the network
Dec 30, 2019
Ansible
michael class=
How to Fix “Shared connection to x.x.xx closed” Ansible Error
Nov 6, 2021
Windows
otwol class=
What is the difference Between the net user,net use and net view Commands in Windows CMD
Aug 3, 2019
Windows
grayson class=
Menu Bar options Are missing In Visual Studio Code.
Aug 23, 2019
Windows
Aditya class=
Net Use Command Usage
Jul 31, 2019
ImageMagick
gibbons class=
Windows : ImageMagick (6.8.1) on Laragon
Apr 6, 2018

Related News in How to add or remove Windows user by Ansible playbook

Related News in How to add or remove Windows user by Ansible playbook

Windows 10 lets Linux run inside Windows after Fall Creators Update
Windows 10 lets Linux run inside Windows after Fall Creators Update
Aug 3, 2017
Non- Windows users frustrated with the performance of OneDrive
Non- Windows users frustrated with the performance of OneDrive
Mar 24, 2017
Google expert fuzzes ports Windows Defender to Linux
Google expert fuzzes ports Windows Defender to Linux
May 26, 2017
A Window inside the Linux Desktop
A Window inside the Linux Desktop
Apr 22, 2017
Linux is too powerful for Windows 10 S, so Microsoft just blocked it
Linux is too powerful for Windows 10 S, so Microsoft just blocked it
May 20, 2017
MicroSoft’s App Store Welcomes Linux to their Subsystem
MicroSoft’s App Store Welcomes Linux to their Subsystem
May 13, 2017
Windows to pull the plug on Vista
Windows to pull the plug on Vista
Mar 18, 2017
Microsoft launches Windows 10 beta for business users
Microsoft launches Windows 10 beta for business users
Apr 8, 2017
Back To Top!
Rank
User
Points

Top Contributers

userNamenaveelansari
135850

Top Contributers

userNameayanbhatti
92510

Top Contributers

userNamehamzaahmed
32150

Top Contributers

1
userNamelinuxhelp
31040

Top Contributers

userNamemuhammadali
24500
Can you help Gibbson ?
How do i run both nginx and apache in same instance on centos

Hi...,

my server is based centos operating system and my webserver is already running on Apache.... i need to run both apache and nginx on same instance ... please help me to implement this concept...

Networking
  • Routing
  • trunk
  • Netmask
  • Packet Capture
  • domain
  • HTTP Proxy
Server Setup
  • NFS
  • KVM
  • Memory
  • Sendmail
  • WebDAV
  • LXC
Shell Commands
  • Cloud commander
  • Command line archive tools
  • last command
  • Shell
  • terminal
  • Throttle
Desktop Application
  • Linux app
  • Pithos
  • Retrospect
  • Scribe
  • TortoiseHg
  • 4Images
Monitoring Tool
  • Monit
  • Apache Server Monitoring
  • EtherApe 
  • Arpwatch Tool
  • Auditd
  • Barman
Web Application
  • Nutch
  • Amazon VPC
  • FarmWarDeployer
  • Rukovoditel
  • Mirror site
  • Chef
Contact Us | Terms of Use| Privacy Policy| Disclaimer
© 2025 LinuxHelp.com All rights reserved. Linux™ is the registered trademark of Linus Torvalds. This site is not affiliated with linus torvalds in any way.