• Categories
    Category
    {{ postCtrl.tags }}
    • {{ category.tag_type }}

      • {{tag.tag_name}}
      • View more
  • Categories
    Category
    {{ postCtrl.tags }}
    • {{ category.tag_type }}

      • {{tag.tag_name}}
      • View more
  • News
  • Tutorials
  • Forums
  • Tags
  • Users
Tutorial News Comments FAQ Related Articles

How to Create and Remove Windows User by using Ansible Playbook on Oracle Linux 8.5

  • 00:42 cat /etc/os-release
  • 00:57 yum list ansible
  • 01:11 yum list python3
  • 01:33 pip3 list | grep pywinrm
  • 01:51 vim /etc/ansible/hosts
  • 02:28 vim useradd.yml
  • 04:22 ansible-playbook useradd.yml --syntax-check
  • 04:37 ansible-playbook useradd.yml
  • 05:24 vim removeuser.yml
  • 06:50 ansible-playbook removeuser.yml --syntax-check
  • 07:12 ansible-playbook removeuser.yml
{{postValue.id}}

To Create and Remove Windows User by using Ansible on Oracle Linux 8.5

Introduction:

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

Procedure:

**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 below command

[root@linuxhelp ~]# cat /etc/os-release
NAME="Oracle Linux Server"
VERSION="8.5"
ID="ol"
ID_LIKE="fedora"

Step 2: Check the availability of Ansible package, python3-pip package, by using the below command

[root@linuxhelp ~]# yum list ansible
ansible.noarch                        2.9.27-1.el8                         @ol8_developer_EPEL
Available Packages
ansible.src                           2.9.27-1.el8                         ol8_developer_EPEL 

[root@linuxhelp ~]# yum list python3
Last metadata expiration check: 1:28:13 ago on Sun 11 Sep 2022 03:22:41 PM IST.
Available Packages
python3.src                         3.6.8-45.0.1.el8                         ol8_baseos_latest
python3.src                         3.6.8-45.0.1.el8                         ol8_appstream    

[root@linuxhelp ~]# pip3 list | grep pywinrm
pywinrm (0.4.3)

Step 3: Create inventory for Windows node system by using the below command

[root@linuxhelp ~]# vim /etc/ansible/hosts
[windows]
192.168.6.104

[windows:vars]
ansible_user=Admin
ansible_password=Linuxc#4
ansible_port=5986
ansible_connection=winrm
ansible_winrm_server_cert_validation=ignore

Step 4: Create playbook for Creating Windows user by using the below command

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

Step 5: Check the syntax of the useradd.yml ansible playbook by using the below command

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

Step 6: Run the useradd.yml playbook by using the below command

[root@linuxhelp ~]# ansible-playbook useradd.yml 

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

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

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

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

Step 7: Create playbook for removing Windows user by using the below command

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

Step 8: Check the syntax of the removeuser.yml ansible playbook by using the below command

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

Step 9: Run the removeuser.yml playbook by using the below command

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


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

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

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

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

Conclusion:

We have reached the end of this article. In this guide, we have walked you through the steps required to Create and Remove Windows User by using Ansible playbook on Oracle Linux 8.5. Your feedback is much welcome.

Tags:
michael
Author: 

Comments ( 0 )

No comments available

Add a comment
{{postCtrl.cmtErrMsg}}

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 a 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.

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 Isaac ?
How to run windows application in linux

I need to run the windows application in my Linux machine, instead of installing from yum repo or any other repos. How to do that..??

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.