How to Install Ansible on Windows

May 30, 2024

Introduction

Ansible is an Infrastructure as Code tool for managing and monitoring remote servers. Ansible requires a Linux-based system to run, which can be an issue if you want to use its features on a Windows system. However, there are multiple methods to install Ansible on Windows.

This tutorial will cover different ways you can install Ansible on Windows.

How to install Ansible on Windows - a tutorial.

Prerequisites

Install Ansible on Windows Using WSL

Windows Subsystem for Linux (WSL) allows users to install different Linux distributions (such as Ubuntu) and use Linux apps and Bash command-line tools directly. This method does not require a virtual machine or dual boot setup.

Install Ansible with WSL by following the steps below:

1. Press the Windows key and type powershell. In the right panel, select the Run as administrator option.

2. Run the following command to install WSL and Ubuntu:

wsl --install

Note: To install a distribution other than Ubuntu, run wsl --list --online to see a list of available distros and use the syntax below to install a specific distro:

wsl --install -d [distro_name]

3. Once the installation completes, Ubuntu automatically launches. Run the following command to update the system repository information:

sudo apt update

4. Install the prerequisite packages that allow you to add the official Ansible PPA:

sudo apt install software-properties-common

5. Add the PPA with the following command:

sudo apt-add-repository ppa:ansible/ansible
Add ansible PPA to WSL Ubuntu installation.

When prompted, press Enter to continue.

6. Once again, update the package repository information after adding the PPA:

sudo apt update

7. Lastly, install Ansible by running:

sudo apt install ansible -y

Wait for the process to complete, and you can start using Ansible.

Note: Check out our tutorial on How to Install Ubuntu on Windows with Hyper-V. Hyper-V allows you to install a distribution of Linux on Windows, including Ubuntu.

Install Ansible on Windows Using Cygwin

Cygwin is a POSIX-compatible environment that lets you run tools and code designed for Unix-like operating systems on Microsoft Windows.

To install Ansible on Windows using Cygwin, follow these steps:

1. Download the Cygwin installation file. This file is compatible with both the 32-bit and 64-bit versions of Windows. It automatically installs the right version for your system.

2. Double-click the downloaded file to run it. On the welcome screen, click Next to continue.

Cygwin welcome screen.

3. Select Install from Internet as the download source and click Next.

Choose Cygwin download source.

4. In the Root Directory field, specify where you want the application installed, then click Next.

Select the root installation directory for Cygwin.

5. In the Local Package Directory field, select where you want to install your Cygwin packages, then click Next.

Select the local package directory.

6. Choose the appropriate Internet connection option. If you are not using a proxy, select Direct Connection. Otherwise, select Use System Proxy Settings or enter the proxy settings manually with the Use HTTP/FTP Proxy. Click Next to continue.

Select internet connection type for Cygwin.

7. Choose one of the available mirrors to download the installation files, then click Next.

Select download mirror for Cygwin.

8. On the Select Packages screen, type ansible in the search bar and press Enter to perform the search. Expand the Admin and Doc categories and double-click the ansible and ansible-doc files to select them.

Click Next to install the packages.

Select which Ansible packages to install.

9. The next screen lets you review the installation settings. To confirm and begin the installation process, click Next.

Review Cygwin installation.

The install wizard downloads and installs all the selected packages, including Ansible.

10. Once the installation is complete, select whether you want to add a Cygwin desktop and the Start Menu icon. Click Finish to close the wizard.

Finish the installation

Install Ansible on Windows Using Linux Virtual Machine

Another way to install Ansible on Windows is to use a virtualization tool and a Linux virtual box. In this example, we will use Oracle VM VirtualBox to set up an Ubuntu virtual machine and install Ansible.

Follow the steps in the sections below.

Step 1: Set up VirtualBox

Follow the steps below to set up VirtualBox on your system:

1. Using a web browser, navigate to the VirtualBox Downloads page. Download the VirtualBox Windows installation file and double-click it to start the installation.

2. Click Next on the welcome screen of the installation wizard to continue.

Oracle VM VirtualBox welcome screen.

3. The next step allows you to select which VirtualBox features you want to install. This is also where you can set the installation location. Click Next to continue.

Choose VirtualBox features.

4. A new screen will warn you that the install wizard needs to reset your network connection. Click Yes to continue.

VBox warning during installation.

5. On the next screen, click Install to begin the installation process and wait until it completes.

Start VirtualBox installation.

Step 2: Create Ubuntu Virtual Machine

The steps below show how to create a new Ubuntu virtual machine:

1. Download the Ubuntu desktop image. In this tutorial, we will use Ubuntu 22.04.

2. On the VirtualBox starting screen, click New.

Create a new Virtual Machine.

3. Type in the name of your virtual machine. If the name contains the word Ubuntu, the operating system dropdown menu automatically updates to Ubuntu (64-bit). If not, you can select the operating system manually using the dropdown menu. Click Next to continue.

Select a name and operating system for your new VM.

4. Use the sliders to set the amount of RAM and number of CPU cores you want the virtual machine to have, and click Next to continue.

Set the amount of RAM and number of CPU cores for your new VM.

Note: By default, Oracle VM VirtualBox assigns 1024MB of RAM to every virtual machine. Make sure you assign enough RAM to your new VM, or it will not work properly.

5. Select a hard disk option for your virtual machine. Choose Create a virtual hard disk now if you are creating a brand new VM. Use the slider to set the hard disk capacity, and click Next to continue.

Set up a hard disk for your new VM.

Note: Just like with RAM, you need to make sure you assign enough hard disk space to your virtual machine.

6. Select the new VM you just created on the left side of the VirtualBox starting screen. Click Start to run the new VM.

Start new VM in VirtualBox.

7. VirtualBox will prompt you to select a start-up disk. Click the button next to the drop-down menu to open the optical Disk Selector and find the Ubuntu ISO you previously downloaded.

Mount the Ubuntu ISO to install it on VirtualBox.

Click the Mount and retry boot button, and the VM boots from the Ubuntu ISO. Follow the steps for installing Ubuntu outlined in our tutorial.

Step 3: Install Ansible

Once you are done installing Ubuntu, open the command terminal (Ctrl + Alt + T) to install Ansible and follow the steps below:

1. Update the local repository information:

sudo apt update

2. Install Ansible with this command:

sudo apt install ansible -y
Install Ansible on Ubuntu VM.

The rest of the installation process is automated.

After you install the tool on your virtual machine, you can configure Ansible by setting up the hosts inventory file and checking the connections.

Conclusion

If you followed the steps in this guide, you now have a copy of Ansible installed on your Windows system. Ansible is a great tool for automating IT tasks such as configuration management, application deployment, and orchestration. You can use it to manage and configure remote servers and plan your CI/CD process.

Next, see how Ansible compares to Saltstack, or read our article to help you decide between Ansible and Jenkins.

Was this article helpful?
YesNo
Bosko Marijan
Having worked as an educator and content writer, combined with his lifelong passion for all things high-tech, Bosko strives to simplify intricate concepts and make them user-friendly. That has led him to technical writing at PhoenixNAP, where he continues his mission of spreading knowledge.
Next you should read
How to Install and Configure Ansible on Ubuntu 20.04
May 30, 2024

Ansible is a management system that helps you manage a large number of servers without the need for any...
Read more
How to Install phoenixNAP BMC Ansible Module
July 24, 2020

Learn how to successfully install the Bare Metal Cloud Ansible module on your control machine. Take a look at...
Read more
What is Bare Metal Cloud
May 20, 2020

This article provides answers to everything you wanted to know about Bare Metal Cloud and how it compares to...
Read more
How to Edit Hosts File on Mac
November 21, 2023

The simplest way to edit the hosts file is by using the Mac Terminal app. Follow the steps in the article...
Read more