How to Install and Configure Ansible on Windows?

Ansible is a popular open-source automation tool that allows system administrators to automate repetitive tasks and manage multiple servers simultaneously. It is widely used for configuration management, application deployment, and task automation. While Ansible is primarily designed for Linux and Unix-based systems, it can also be installed on Windows. In this article, we will guide you through the process of installing and configuring Ansible on Windows.

Requirements

Before we begin, make sure your Windows machine meets the following requirements

  • A Windows operating system (Windows 10, Windows 11, or Windows Server 2016 or later)

  • A minimum of 4GB RAM

  • PowerShell version 5.1 or later

  • Python 3.8 or later

Step 1: Install Python

The first step is to install Python on your Windows machine. You can download the latest version of Python from the official website. Once the download is complete, run the Python installer and follow the instructions to complete the installation. Make sure to check the option to add Python to the PATH environment variable during installation.

To verify Python installation, open PowerShell and run

python --version

Step 2: Install pip

Once Python is installed, you will need to install pip, a package manager for Python. Open a PowerShell window as an administrator and run the following command

python -m ensurepip --default-pip

This command will install pip and add it to the PATH environment variable.

Step 3: Install Ansible

Now that Python and pip are installed, you can use pip to install Ansible. In the same PowerShell window, run the following command

pip install ansible

This command will download and install Ansible and its dependencies. Once installation is complete, you can verify that Ansible is installed by running

ansible --version

Step 4: Configure Ansible

Before you can start using Ansible, you need to configure it by creating an inventory file and setting up connection methods. An inventory file is a list of hosts that Ansible can manage.

Creating an Inventory File

Create a new file named inventory.ini and list the IP addresses or hostnames of the Windows machines you want to manage

[windows]
192.168.1.101
192.168.1.102

[windows:vars]
ansible_user=Administrator
ansible_password=your_password
ansible_connection=winrm
ansible_winrm_server_cert_validation=ignore

Save the inventory file in a location of your choice.

Setting Up WinRM (Recommended)

Windows Remote Management (WinRM) is the preferred method for connecting to Windows machines. On each target Windows machine, run the following commands in PowerShell as Administrator

# Enable WinRM
winrm quickconfig -y

# Allow unencrypted traffic (for testing only)
winrm set winrm/config/service '@{AllowUnencrypted="true"}'

# Set authentication methods
winrm set winrm/config/service/auth '@{Basic="true"}'

For production environments, configure HTTPS and proper authentication instead of allowing unencrypted traffic.

Step 5: Test Ansible Connection

Now that Ansible is installed and configured, you can test the connection by running

ansible windows -i inventory.ini -m win_ping

This command will ping the Windows machines listed in your inventory file. A successful response indicates that Ansible can communicate with the target hosts.

Key Configuration Tips

Configuration Description Best Practice
Connection Method Use WinRM instead of SSH More secure and efficient for Windows
Authentication Configure Kerberos or NTLM Avoid basic auth in production
Encryption Enable HTTPS for WinRM Encrypt all communication
Inventory Variables Use group variables Centralize common settings

Best Practices

  • Use Ansible Vault Encrypt sensitive data like passwords using ansible-vault command to protect credentials.

  • Install Required Modules Install pywinrm for WinRM connectivity: pip install pywinrm

  • Use Roles Organize playbooks into reusable roles for better maintainability and code reuse.

  • Test Playbooks Use --check mode to simulate execution without making actual changes.

  • Version Control Store playbooks and inventory files in Git for tracking changes and collaboration.

Example Playbook

Here's a simple playbook to test Windows automation

---
- name: Windows Server Configuration
  hosts: windows
  tasks:
    - name: Check Windows version
      win_shell: Get-ComputerInfo | Select-Object WindowsProductName
      register: windows_info
    
    - name: Display Windows version
      debug:
        msg: "{{ windows_info.stdout }}"

Save this as test-playbook.yml and run it with

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

Conclusion

Installing and configuring Ansible on Windows enables powerful automation capabilities for managing Windows infrastructure. By following these steps and best practices, you can effectively automate repetitive tasks, manage multiple servers, and improve operational efficiency. Remember to prioritize security by using proper authentication methods and encrypting sensitive data with Ansible Vault.

Updated on: 2026-03-17T09:01:38+05:30

25K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements