Operations 4 min read

Using Ansible Windows Modules for Common Administrative Tasks

This guide demonstrates how to use various Ansible Windows modules—such as win_ping, raw, win_copy, win_unzip, win_service, win_command, win_file, win_user, win_shell, and win_reboot—to retrieve network information, transfer and unzip files, manage services, manipulate files, create users, and reboot remote Windows hosts.

Practical DevOps Architecture
Practical DevOps Architecture
Practical DevOps Architecture
Using Ansible Windows Modules for Common Administrative Tasks

Firewall ports : Ensure that ports 5986 and 5985 are open on the firewall.

Windows common modules

Ping module ansible windows -m win_ping Retrieve network interface information using a specific inventory file ansible -i win_hosts windows -m raw -a "ipconfig" Retrieve network interface information using the default inventory ansible windows -m raw -a "ipconfig" Copy files to a remote Windows host

ansible windows -m win_copy -a 'src=/etc/passwd dest=F:\file\passwd'
ansible windows -m win_copy -a "src=/usr/local/src/PayChannels20.35.zip dest=D:\Tomcat\webapps\PayChannels20.35.zip"
ansible windows -m win_copy -a "src=/usr/local/src/SupplierPay.zip dest=D:\SupplierPay.zip"

Unzip a .zip file on the remote Windows host (source file must exist)

ansible windows -m win_unzip -a "creates=no src=D:\Tomcat\webapps\PayChannels.zip dest=D:\Tomcat\webapps"

Unzip to D: drive

ansible windows -m win_unzip -a "creates=no src=D:\SupplierPay.zip dest=D:"

Restart a service on the remote Windows host

ansible windows -m win_service -a "name=Tomcat state=restarted"

Restart Redis using a .bat command

ansible windows -m win_command -a "chdir=D:\Redis server\start.bat"

Execute commands with win_command module

Start Redis

ansible windows -m win_command -a "chdir=D:\Redis server.bat "

Delete files or directories

ansible windows -m win_file -a "dest=D:\Redis server\log\ state=absent"
ansible windows -m win_file -a "dest=D:\Redis server\logs\ state=absent"

Create a user ansible windows -m win_user -a "name=aa passwd=123456" Create an administrator user named user1 with remote desktop access

ansible windows -m win_user -a "name=user1 password=123 groups='Administrators,Remote Desktop Users'"

First method to reboot the remote host ansible windows -m win_shell -a "shutdown -r -t 1" Second method to reboot the remote host

ansible windows -m win_reboot
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

AutomationDevOpsWindowsAnsibleRemoteManagement
Practical DevOps Architecture
Written by

Practical DevOps Architecture

Hands‑on DevOps operations using Docker, K8s, Jenkins, and Ansible—empowering ops professionals to grow together through sharing, discussion, knowledge consolidation, and continuous improvement.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.