AnsiblePilot — Master Ansible Automation

AnsiblePilot is the leading resource for learning Ansible automation, DevOps, and infrastructure as code. Browse over 1,400 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 8 Ansible books published by Apress and Leanpub including "Ansible for VMware by Examples" and "Ansible for Kubernetes by Example", 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.

Can Ansible Be Used to Manage Windows Systems?

By Luca Berton · Published 2024-01-01 · Category: installation

Explore how Ansible can be used to manage and automate Windows systems with ease, leveraging WinRM, modules, and playbooks.

Ansible is a highly flexible automation tool that can manage Windows systems alongside Linux and other platforms. This article explains how Ansible enables Windows automation, its prerequisites, and key use cases.

Can Ansible Manage Windows Systems?

Yes, Ansible can manage and automate Windows systems efficiently. Using Windows Remote Management (WinRM) or SSH, Ansible interacts with Windows machines to execute tasks like configuring services, installing software, and managing files.

See also: Can Ansible Manage Windows? Complete Windows Automation Guide

Setting Up Ansible for Windows

1. Enable WinRM on Windows Hosts

WinRM allows Ansible to communicate with Windows machines. To enable it: Open PowerShell as Administrator. Execute the following commands:
winrm quickconfig
winrm set winrm/config/service/auth '@{Basic="true"}'
winrm set winrm/config/service '@{AllowUnencrypted="true"}'
Set-Item wsman:\localhost\Client\TrustedHosts -Value "<Ansible_Control_Node_IP>"

2. Install Required Libraries on Ansible Control Node

Install the pywinrm library to enable WinRM communication:
pip install pywinrm

3. Configure Inventory for Windows

Add Windows hosts to the Ansible inventory file:
[windows]
windows_host ansible_host=192.168.1.10 ansible_user=Administrator ansible_password=your_password ansible_connection=winrm

Windows Modules in Ansible

Ansible provides a wide range of modules specifically for managing Windows systems. These modules simplify tasks such as service configuration, user management, and software installation.

Examples of Windows Modules

win_service: Manage Windows services.
   - name: Ensure IIS service is running
     win_service:
       name: W3SVC
       state: started
   
win_package: Install or uninstall software.
   - name: Install Chrome
     win_package:
       path: "https://dl.google.com/chrome/install/GoogleChromeStandaloneEnterprise.msi"
   
win_user: Manage user accounts.
   - name: Create a new user
     win_user:
       name: dev_user
       password: StrongPassword123!
       state: present
   
win_shell: Run PowerShell or command-line commands.
   - name: Run a PowerShell command
     win_shell: Get-Process
   
win_file: Manage files and directories.
   - name: Create a directory
     win_file:
       path: C:\Temp
       state: directory
   

See also: Ansible on Windows: Complete Guide to Windows Automation (2026)

Use Cases for Ansible on Windows

Application Deployment: Automate software installations and updates. Service Management: Start, stop, or restart services. Configuration Management: Enforce consistent configurations across Windows systems. User Management: Add, update, or remove user accounts and groups. File Management: Manage files, directories, and permissions.

Running Ansible Playbooks for Windows

Once the inventory and playbooks are configured, run a playbook targeting Windows systems:

ansible-playbook -i inventory.ini windows-playbook.yml

Example Playbook to Configure Windows

- hosts: windows
  tasks:
    - name: Install IIS
      win_feature:
        name: Web-Server
        state: present

- name: Start IIS service win_service: name: W3SVC state: started

See also: Can Ansible Automate Windows? Complete WinRM + SSH Setup Guide (2026)

Best Practices for Windows Automation with Ansible

Secure Credentials: Use Ansible Vault to encrypt sensitive data like passwords. • Validate Configurations: Test playbooks in a non-production environment. • Leverage Roles: Use roles to modularize and organize tasks.

Conclusion

Ansible is an excellent choice for managing Windows systems, offering simplicity and flexibility. With its robust set of modules and playbooks, you can automate Windows tasks alongside other platforms, streamlining your infrastructure management.

Learn More About Managing Windows with Ansible

Related Articles

encrypting variables with Ansible Vaulthow Ansible inventory worksrole directory layout in Ansibleconfiguring Windows services via Ansible

Category: installation

Browse all Ansible tutorials · AnsiblePilot Home