in

How to Install Ansible on Windows: The Complete Guide

Ansible has become one of the most popular tools for IT infrastructure automation over the last few years. Originally developed for Linux management, Ansible is now capable of automating Windows environments as well thanks to increased support from Microsoft and the Ansible community.

However, getting Ansible running on Windows still requires some additional configuration compared to Linux. In this comprehensive guide, we‘ll cover everything you need to get Ansible installed and operational on Windows.

By the end, you‘ll be able to use Ansible to automate deployments, configuration management, and more across your Windows servers and devices. Let‘s dive in!

Why Choose Ansible for Windows Automation?

Before we get our hands dirty with the installation process, let‘s look at why Ansible is a great choice for automating Windows:

Powerful automation capabilities

Ansible allows you to automate just about any IT process – configuration management, application deployments, cloud provisioning, network automation, and more. Ansible works great for both Linux and Windows environments despite their differences.

Idempotent playbooks

Ansible playbooks are idempotent, which means you can run them multiple times safely without side effects. This makes playbooks reliable and repeatable, unlike bash scripts that may break if run multiple times.

No agents needed

Ansible does not require any daemons or background services to be installed on target nodes. It connects directly via SSH or WinRM to execute automation tasks. This makes deployment and maintenance easy.

Maturing Windows support

Windows support used to be Ansible‘s weak spot, but thanks to Microsoft‘s increased involvement in open source and faster Windows update cycles, Ansible‘s Windows capabilities have expanded significantly in the last few years.

750+ modules for all tasks

Ansible has an extensive library of over 750 modules covering automation tasks like cloud, containers, databases, files, packaging, system, utilities, and much more. Many modules support both Linux and Windows platforms.

Simpler than PowerShell DSC

While PowerShell DSC is Microsoft‘s native automation tool, Ansible provides a simpler and more human-readable automation language through YAML playbooks. Ansible is easier to use for most infrastructure automation tasks.

No coding skills required

Ansible uses an easy YAML-based playbook language that anyone can understand, not complex coding skills. You can get started with Ansible automation without programming experience.

According to Red Hat‘s 2021 survey, Ansible usage grew over 65% from 2020 to 2021, indicating its rising popularity for automation. Given Ansible‘s capabilities, it‘s no surprise that Ansible is being adopted increasingly for Windows automation as well.

Now let‘s see how we can get Ansible installed on Windows.

Installing Ansible on Windows Using Cygwin

The easiest way to get Ansible running on Windows is by utilizing Cygwin – a Linux-like environment for Windows that provides UNIX tools to run natively on Windows.

Cygwin gives us a simple way to install Ansible and its Linux dependencies without needing a full VM or dual boot.

Here are the step-by-step instructions to install Ansible using Cygwin:

  1. Download the Cygwin installer from https://cygwin.com/install.html. Choose the 32-bit or 64-bit version based on your Windows OS version.

  2. Run the Cygwin setup executable and step through the installation wizard:

    • Choose "Install from Internet" for the download source. This will download Cygwin packages directly from the internet.

    • Specify the root directory where you want Cygwin installed.

    • Choose a local directory to store all downloaded Cygwin packages.

    • Select "Direct Connection" if you don‘t need a proxy.

    • Pick any Cygwin mirror server to download packages from.

  3. In the package selection step, choose "View" as "Full" to see the complete list of available Cygwin packages. Search for "ansible" and select the latest Ansible package to install. The ansible-doc package is optional documentation.

  4. Complete the remaining installer steps to confirm your package selections. Cygwin will now download and install Ansible and all its dependencies.

  5. Once the Cygwin installation completes, search for "Cygwin Terminal" and open the Cygwin terminal.

  6. Verify Ansible installation by running:

     ansible --version

This will display the installed Ansible version if it was installed correctly. And that‘s it – Ansible is now installed and ready to use on Windows via the Cygwin Linux environment!

Benefits of using Cygwin:

  • Very quick and easy Ansible installation on Windows.

  • All Linux dependencies handled automatically.

  • Access to many other Linux tools if needed.

  • Active Cygwin community for support.

The downside is Cygwin provides a simulation of Linux, not a full Linux OS. There are still Windows limitations like drive letters and some permission issues. For full Linux compatibility, installing Ubuntu directly on Windows works better.

Installing Ansible on Windows 10 Ubuntu Bash

Windows 10 introduced native support for running Linux distributions on Windows via the Windows Subsystem for Linux (WSL). This lets you install a distro like Ubuntu and access it directly within Windows.

Using Ubuntu bash on Windows 10, we can install Ansible and run it with full Linux compatibility right on Windows itself.

Here are the steps to install Ansible on Ubuntu bash on Windows 10:

  1. Open Windows Features and enable "Windows Subsystem for Linux". Reboot if prompted.

  2. Install Ubuntu 20.04 LTS (or other preferred version) from the Microsoft Store. Open the app when installed.

  3. Create a username and password for the default Linux user account. You can also set a root password using sudo passwd root.

  4. Update apt packages and install Ansible:

     sudo apt-get update
     sudo apt-get install software-properties-common
     sudo apt-add-repository ppa:ansible/ansible
     sudo apt-get update 
     sudo apt-get install ansible
  5. Press Y when prompted to confirm Ansible installation.

  6. Verify installation by running ansible --version.

This installs the latest Ansible version directly on Ubuntu on Windows 10, ready for immediate use. You can now run playbooks and manage Windows servers right from Ubuntu bash!

Benefits of using Ubuntu bash:

  • Full Linux environment with better compatibility than Cygwin.

  • Native speeds and performance since it uses Hyper-V, not emulation.

  • Direct access to Linux tools, shells, and utilities within Windows.

  • Active Ubuntu community for support and documentation.

The only caveat is that Windows Subsystem for Linux requires Windows 10 or higher. But for the best Linux experience on desktop Windows, Ubuntu bash is recommended if your Windows version allows it.

Tips for Running Ansible on Windows

Here are some additional tips for getting the most out of Ansible on Windows once you have it installed:

  • Use PowerShell instead of Command Prompt for running Ansible commands. PowerShell provides much better functionality.

  • Ensure Windows hosts have PowerShell 3.0+ and .NET 4.0+ for best Ansible support.

  • Manage Windows firewall rules properly to allow Ansible connections on the configured port – SSH or WinRM.

  • Use the win_ping module to test connectivity with Windows hosts.

  • Review the Windows-specific usage details in Ansible‘s official documentation.

  • Ask questions on Ansible‘s active community discussion forums for Windows help.

  • Take advantage of existing Windows roles on Ansible Galaxy to avoid reinventing the wheel.

According to Red Hat, Windows automation using Ansible grew over 63% from 2020 to 2021. Ansible on Windows skills are becoming highly sought after as organizations automate hybrid environments.

Further Learning Resources

To take your Ansible Windows automation skills to the next level, refer to these helpful learning resources:

Summary

We‘ve now covered multiple methods to get Ansible installed on Windows – either via Cygwin or native Ubuntu bash on Windows 10.

You should have Ansible up and running ready to start automating configurations, deployments, and infrastructure management across your Windows servers and workstations.

Ansible greatly simplifies managing the automation of complex multi-OS environments by providing a consistent platform across Linux, Windows, and networking devices. Be sure to refer to the learning resources mentioned to further enhance your Ansible on Windows skills.

Feel free to reach out in the comments if you have any additional questions as you start your Ansible journey on Windows! I‘ll be happy to help out.

AlexisKestler

Written by Alexis Kestler

A female web designer and programmer - Now is a 36-year IT professional with over 15 years of experience living in NorCal. I enjoy keeping my feet wet in the world of technology through reading, working, and researching topics that pique my interest.