AUTOMATESQL
Back to all guides
January 22, 2025•7 min

3 Ways to Install Ansible on Windows

Jan 22, 2025

How to run ansible from a windows machine

How do I install Ansible on Windows?

This is a common question for those of you who are just getting started with Ansible or are curious about how to use it from a Windows machine.

When I talk about installing Ansible, I'm referring to installing the Ansible control node—the machine from which you run ansibleor ansible-playbook commands.

Since Ansible is not directly supported on Windows, you can't just install it natively. But there are three approaches that let you keep your Windows machine without having to switch over to macOS or Linux.

  1. Windows Subsystem for Linux (WSL)
  2. A local Linux virtual machine
  3. A containerized environment using Docker and Red Hat Universal Base Image (UBI)

Let's break these methods down.

1. Install Ansible Using Windows Subsystem for Linux (WSL)

Microsoft's Windows Subsystem for Linux (WSL) is the quickest, most straightforward way to get a Linux environment on Windows (in fact, this is the method I use in the Ansible for SQL Server DBAs: Level 1 course). If you're running Windows 11, you can seamlessly manage Linux tools without leaving your primary OS. I've already written a detailed post on how to install Ansible in WSL, which you can find here. Below are the general steps:

  1. Enable WSL
  2. Install a Linux Distro ( Ubuntu works well**)**
  3. Launch the Distro, update packages, and install Ansible (and optional tools like ansible-lint)
  4. Start creating playbooks and using Ansible—Visual Studio Code, along with the Ansible plugin, is a great choice when working with Ansible's YAML files.

Advantages of WSL

  • Seamless integration with Windows tools.
  • Lightweight compared to a full virtual machine.
  • Ideal if you want a near-native Linux environment on Windows.

2. Install Ansible on a Linux Virtual Machine

This method requires the use of a type-2 hypervisor—Hyper-V, Oracle Virtualbox or VMWare Workstation Pro for example. While this approach uses more system resources, you get greater isolation and the ability to create VM snapshots (great for testing/rollback).

  1. Build a VM running your preferred Linux distro (Ubuntu, CentOS, RHEL, etc.).
  2. Install Ansible in the VM just as you would on a physical Linux machine.

Technical Screenshot

3. Build a Containerized Ansible Environment with Docker Desktop and Red Hat Minimal UBI

A third approach—one that closely resembles Ansible Automation Platform execution environments—is to run Ansible inside a Docker container. Red Hat's Universal Base Images (UBI) are a reliable foundation for this.

Why Containerize?

  • Lightweight & Reproducible: Spin up/down quickly and version your environment easily.
  • Minimal Overhead compared to a full VM.
  • Fast Testing of Different Ansible Versions or dependencies.

Technical Screenshot

I've used the following steps as a fast-track method to get started with Docker Desktop and Ansible.

Steps for Building Your Container

  1. Install Docker Desktop (Download—https://desktop.docker.com/win/main/amd64/178610/Docker%20Desktop%20Installer.exe). During installation, select "Use WSL instead of Hyper-V" (you'll need WSL to support Linux-based containers).
  2. Restart your PC after installing Docker Desktop and WSL.
  3. Start Docker Desktop. Accept licenses and choose the recommended settings. You can skip the sign-in and survey.
  4. Create a Work Folder. For example: C:\AnsibleContainer. Inside this folder, create a file named dockerfile (with no extension). Dockerfiles contain instructions for Docker to read from when building images. They are text files that contain all the commands used to assemble an image. We'll keep ours simple. Copy and paste the following text into the file (using Notepad is fine).

Before moving on to the next step, here's what we're telling Docker to build using this set of commands:

Technical Screenshot

This Dockerfile creates a minimal Red Hat 9.5-based container, installs all dependencies required for Ansible (including Kerberos and WinRM support), and sets up a non-root user environment. By the end, you have a lightweight container image prepped for running Ansible against both Linux and Windows managed hosts.

Back to the build.

  1. Open a command prompt.
  2. Navigate to C:\AnsibleContainer (where your Dockerfile is stored).
  3. Run:docker build --build-arg USERNAME=YourUserName -t ansible-ubi .

After a few minutes, you'll have a new image named ansible-ubi. Be sure to set the USERNAME variable to the username you want to use within the container.

Technical Screenshot

Run a Container Interactively

Now you can run the container and "bind-mount" your local C:\AnsibleContainer folder so you can share files between Windows and the container:

  • At the command prompt, run:docker run --name ansible_container -it --rm -v C:\AnsibleContainer:/ansible ansible-ubi /bin/bash
  • Once inside the container, check your Ansible version: ansible --version
  • Switch to the /ansible directory by running: cd /ansible
  • From here, you can create your inventory file, create additional folders, or begin creating your playbooks.
  • To exit the container, type exit.

The image can be removed either by using the Docker Desktop GUI or the "docker rmi" command.

Congratulations! You've built a containerized environment that can manage both Linux and Windows hosts (it supports WinRM via pywinrm).

See it in action: