Ansible is widely recognized for its ability to manage Linux systems, but can it run on Windows? The short answer is yes, with certain configurations. This article explores how Ansible works on Windows, its requirements, and how to set it up for automation workflows.

Can Ansible Run on Windows?

Ansible is primarily designed to run on Linux-based control nodes. However, with tools like the Windows Subsystem for Linux (WSL) or a virtual machine, it can run effectively on a Windows system. Ansible can also manage Windows target nodes directly using protocols like WinRM.

Key Points:

  • Ansible cannot run natively on Windows as a control node.
  • Use WSL or a virtual machine for running Ansible on Windows systems.
  • Ansible can manage Windows systems as target nodes.

Setting Up Ansible on Windows Using WSL

Windows Subsystem for Linux (WSL) enables you to run a Linux environment directly on a Windows machine. Follow these steps to set up Ansible on Windows using WSL:

1. Install WSL

  1. Open PowerShell as Administrator.

  2. Run the following command to install WSL:

    wsl --install
    
  3. Restart your system if prompted.

2. Install a Linux Distribution

After installing WSL, choose a Linux distribution (e.g., Ubuntu) from the Microsoft Store.

3. Update and Install Ansible

  1. Open the installed Linux distribution.
  2. Update the package manager:
    sudo apt update && sudo apt upgrade
    
  3. Install Ansible:
    sudo apt install ansible -y
    

4. Verify Ansible Installation

Run the following command to check the Ansible version:

ansible --version

Running Ansible on Windows Using a Virtual Machine

Alternatively, you can set up a Linux virtual machine using tools like VirtualBox, VMware, or Hyper-V. Once the VM is running, install Ansible as you would on a native Linux system.

Managing Windows Systems with Ansible

Ansible can manage Windows target systems using Windows Remote Management (WinRM). Follow these steps to configure a Windows system for management:

1. Enable WinRM

  1. Open PowerShell as Administrator.
  2. Run 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 pywinrm on the Ansible Control Node

Install the pywinrm Python library for WinRM communication:

pip install pywinrm

3. Configure Ansible Inventory

Add the Windows system to your inventory file:

[windows]
windows_host ansible_host=192.168.1.10 ansible_user=Administrator ansible_password=your_password ansible_connection=winrm

4. Run a Playbook

Execute a playbook to manage the Windows system:

ansible-playbook -i inventory.ini playbook.yml

Best Practices for Running Ansible on Windows

  1. Use WSL for Simplicity: WSL provides a lightweight and efficient way to run Ansible on Windows.

  2. Secure Communication: Use encrypted communication methods like HTTPS or Kerberos for WinRM.

  3. Test Configurations: Validate the setup in a test environment before deploying in production.

  4. Leverage Collections: Use Windows-specific collections like ansible.windows for pre-built modules.

Conclusion

While Ansible cannot run natively on Windows as a control node, using tools like WSL or virtual machines makes it possible to run Ansible on a Windows machine effectively. Additionally, Ansible’s robust support for managing Windows target nodes ensures comprehensive automation capabilities across platforms.

Learn More About Ansible and Windows

Subscribe to the YouTube channel, Medium, and Website, X (formerly Twitter) to not miss the next episode of the Ansible Pilot.

Academy

Explore more Ansible and Windows integration in Ansible by Examples.

BUY the Complete PDF BOOK to easily Copy and Paste the 250+ Ansible code

Support this project by contributing today.

Patreon Buy me a Pizza