sodcalculator

10 Tech How-To

Install Ansible on Windows: The Real Way

Guide 10-4963 · Updated · Step by step

You cannot install Ansible directly on Windows as a native package, but you can run it on Windows through the Windows Subsystem for Linux (WSL) or in a Linux virtual machine. This article explains both options in detail, including setup steps, limitations, and alternatives, so you can manage servers from a Windows machine.

Why Ansible Doesn’t Run Natively on Windows

Ansible is built on Python and relies on Unix-specific features like SSH, POSIX file permissions, and process forking. The control node (the machine that runs Ansible commands) is expected to be a Linux or macOS system. While Python itself is cross-platform, Ansible’s core modules and the way it handles connections are not designed for Windows. The official Ansible documentation states that Windows cannot be used as a control node, and this is not a limitation that can be easily patched.

Option 1: Windows Subsystem for Linux (WSL)

The most common and recommended way to run Ansible on Windows is to install WSL, which gives you a full Linux distribution that runs directly on Windows. Here’s how to set it up:

  1. Open PowerShell as Administrator and run wsl --install. This installs WSL2 and the default Ubuntu distribution.
  2. Restart your computer when prompted.
  3. Launch Ubuntu from the Start menu. It will finish the installation and ask you to create a Linux username and password.
  4. Update the package list and install Ansible with: sudo apt update && sudo apt install ansible
  5. Verify the installation with ansible --version.

After this, you can run Ansible commands from the Ubuntu terminal. Your Windows files are accessible under /mnt/c/, so you can keep your playbooks in a Windows folder and run them from WSL. This method works well because it gives you a real Linux environment without needing a separate virtual machine.

Option 2: Linux Virtual Machine

If you prefer a more isolated environment or need to run Ansible as part of a larger Linux toolchain, a virtual machine is a solid choice. Tools like VirtualBox or VMware Workstation Player allow you to run a full Linux distribution on your Windows desktop. You would then install Ansible inside that VM using the same commands as above. This approach uses more system resources than WSL but provides a complete Linux experience, which can be helpful if you also need to test network configurations or use GUI tools.

Option 3: Docker on Windows

Docker Desktop for Windows can run Linux containers, and you can use an Ansible control node image from Docker Hub. This is a lighter alternative to a full VM, but it requires Docker Desktop to be running whenever you want to use Ansible. You would create a container that has Ansible installed and then execute commands inside it. This method is useful for CI/CD pipelines or if you want a disposable environment, but it adds complexity for everyday use.

What About the Ansible Windows Modules?

There is a common confusion between running Ansible on Windows and managing Windows with Ansible. Ansible can manage Windows hosts from a Linux control node using PowerShell remoting (WinRM) or SSH. This is a well-supported feature, and you can use modules like win_ping and win_service to control Windows servers. However, this does not mean Ansible itself runs on Windows—it only means the targets can be Windows machines. If your goal is to manage Windows servers, you still need a Linux control node, which can be your WSL installation.

Common Problems and Solutions

When using WSL, users often encounter a few issues:

  • File permission errors when working with files on /mnt/c/. Fix this by moving your playbooks to the Linux filesystem (e.g., ~/ansible) or by adjusting the WSL mount options.
  • SSH key permissions are too open. Ansible requires private keys to have strict permissions. Run chmod 600 ~/.ssh/id_rsa to fix this.
  • Networking differences between WSL1 and WSL2. WSL2 uses a virtual network adapter, which can affect how you reach other machines. Use WSL2 for better compatibility, and check your firewall settings if connections fail.
  • Python version conflicts if you have multiple Python installations. Ansible in WSL uses the Linux Python, which is separate from any Windows Python, so this is rarely an issue.

Alternatives to Running Ansible on Windows

If you cannot use WSL or a VM, consider these alternatives:

  • Ansible Tower / AWX: These are web-based interfaces that run Ansible on a central Linux server. You can access them from any browser, including one on Windows.
  • CI/CD pipelines: Use GitHub Actions, GitLab CI, or Azure DevOps to run Ansible playbooks on Linux runners. You can trigger them from your Windows machine via git push.
  • Remote control node: Rent a small Linux server (e.g., a cloud VM) and SSH into it from Windows. This is similar to using a VM but hosted elsewhere.

How to Choose the Right Option

Your choice depends on your workflow:

  • If you are a developer who wants to run Ansible locally, WSL is the easiest and most integrated solution.
  • If you need a full Linux environment for testing or other tools, a VM is better.
  • If you only run Ansible occasionally or in a team, a CI/CD pipeline or a remote control node may be more practical.

Consider your system resources: WSL is lightweight, while a VM requires more RAM and CPU. Also, think about whether you need to access Windows files directly—WSL makes that easy, but a VM is more isolated.

Frequently Asked Questions

Can I install Ansible using pip on Windows?
No. Even if you install Python and pip on Windows, Ansible’s dependencies (like PyYAML and cryptography) may work, but the core functionality will fail because Ansible relies on Unix-specific modules. The official recommendation is to use WSL or a VM.

Does Ansible work with PowerShell on Windows?
Ansible can manage Windows targets via PowerShell remoting, but the control node must be Linux. You can write playbooks that use PowerShell commands, but you cannot run the Ansible engine itself in PowerShell.

Is WSL2 faster than a VM for Ansible?
WSL2 has a lightweight virtual machine that boots quickly and uses less memory than a full VM. For most Ansible tasks, the performance difference is negligible. WSL2 is generally recommended for convenience.

Can I use Ansible from Git Bash or Cygwin on Windows?
These tools provide a Unix-like environment, but they do not fully replicate Linux. Ansible may partially run, but you will encounter issues with SSH and file handling. It is not a supported configuration.

Do I need to install Ansible on every Windows machine I manage?
No. Ansible is agentless; you only install it on the control node. The managed Windows machines just need to have PowerShell and WinRM or SSH enabled.

What is the easiest way to test Ansible on Windows?
Install WSL and run a simple ping against your localhost or a test Linux machine. This takes less than an hour and gives you a full working environment.

Related

General steps for current mainstream versions; menus can differ by device and version. See the disclaimer or report an error.

More in this bed

The whole Tech How-To bed →