Installing Ansible on Ubuntu / Windows – Ansible Tutorial Video 2

Last updated on September 22nd, 2023 at 10:57 am.

Installing Ansible on Ubuntu - Windows WSL - Ansible Tutorial Video 2

In this step-by-step guide, we’ll walk you through how to install Ansible on Ubuntu/Windows using Windows Subsystem for Linux (WSL) running Ubuntu 22.04. By the end of this video/post you will have Ansible running on Ubuntu. If you are on Windows, of course, use WSL.

Table of Contents

Step 1: Enable WSL on Windows

Before installing Ansible on Windows, you need to make sure (Windows Subsystem for Linux) WSL is enabled. Windows Subsystem for Linux lets you run Linux distros on Windows.

To enable WSL:

  1. Open your Windows search and type “Turn Windows features on or off.”
  2. Look out for “Windows Subsystem for Linux” and make sure it’s checked to enable it.
  3. Click “OK” and Windows will install the necessary components.
  4. Important : Ensure virtualization is enabled on your BIOS.-

Step 2: Install Ubuntu on WSL

After enabling WSL, you need to install Ubuntu 22.04. We’ll install Ansible on Ubuntu.

How to install Ubuntu on WSL:

  1. Open the Microsoft Store.
  2. Search for “Ubuntu” and select Ubuntu 22.04.
  3. Click “Get” to start the download and installation of Ubuntu.

Step 3: Set Up Your Ubuntu

Once Ubuntu is installed successfully, open it just like you would open any other Windows application. It will prompt you to create a new username and password. Use a name and password you can remember. That’s it.

Step 4: Update Ubuntu

In the Ubuntu terminal of WSL, type the following to update all packages.

sudo apt update && sudo apt upgrade -y

This will take a while depending on your connectivity.

Step 5: Installing Ansible

Finally, let’s install Ansible! There are a couple of ways to do this:

Option 1: Installing via the Package Manager

You can install Ansible using the Debian/Ubuntu package manager. However, to get the latest versions of Ansible, we need to add the Ansible PPA first.

sudo apt update && / 
sudo apt install software-properties-common && /
sudo add-apt-repository --yes --update ppa:ansible/ansible && /
sudo apt install ansible

Confirm Ansible installation by doing:

ansible --version

Option 2: Installing via pip (Python Package Manager)

If you prefer to have the latest version of Ansible or want more control, you can use pip:

  1. Install pip and Python 3 (if not already installed in your system):

sudo apt install python3 python3-pip

  1. Install Ansible using pip:

pip3 install ansible

Step 6: Confirm Ansible Installation

To confirm that Ansible is installed, check the version. Check ansible version by running the following command:

ansible --version

You should see the Ansible version displayed on your screen.

And that’s it! You’ve successfully installed Ansible on your Windows machine using Windows Subsystem for Linux. If you are on Ubuntu, the installation is the same, except for the fact that you don’t need WSL (duuh!).


Video captions for this Ansible installation video

Let’s move on to the next part, and the next part is installing Ansible. To install Ansible, whether you’re on a Mac, Windows, or Linux, the first option is you can install Ansible via pip. And of course, if you have Python installed on your machine, you can install Ansible via pip. Our second option is for anyone with Linux, even on Windows. That’s what we’re going to do. We’re going to install Ansible via WSL, and I’m going to install it on Ubuntu. So, if you’re on a Mac or Windows, and you can install a virtual environment and use that to install Ansible. There are lots of ways you can get a virtual environment on your system. You can use VirtualBox and install a virtual machine. You can use Vagrant, and I’ll use Vagrant with Windows as my managed nodes. Of course, I would have loved to do this tutorial on Linux, but I prefer to use Camtasia to record my videos. I just wanted to address that in this video. Why, when I’m doing an initial server setup for a Linux system, I use Windows to record sometimes. That’s because of Camtasia. I just prefer to record and edit with Camtasia.

Since I’m on Windows, I’m going to install Ubuntu on WSL. If you’re on Windows, that’s the same path you should take because Ansible doesn’t run natively on Windows. If you’re on Linux, any Linux distribution, it doesn’t matter. You can install Ansible via the package manager, or you can install Python and then install Ansible. So, in this case, let’s go to WSL. If your WSL is not enabled, just make sure you enable it. You can just do a Google search for how to enable WSL on Windows. It’s not a big process nowadays if you’re using the latest updated Windows. Then it’s not a difficult process. In my case, WSL is already installed. I don’t know if I’ve installed Ubuntu yet because I want to use Ubuntu. I’ll just go to the Microsoft Store and I will search for Ubuntu.

Let’s just do a search and see all the options. Here we have Ubuntu. Yeah, I will go with 20.04. Just click on it, click on “Get.” So, I have WSL already turned on. Let it download, and then I’m just going to open it like a normal app, and you’re going to see what you can do next. So, for you to enable WSL on Windows, make sure that virtualization is enabled in your BIOS. You can check for virtualization. I’m here on Windows 10.

If I go to the task manager…

If you go to the task manager and you look at “Performance”…

You look somewhere here; you’ll see “Virtualization enabled.” If this is not enabled, you need to go into your BIOS and then enable it. Just Google how to do it for your motherboard, for your specific computer. This needs to be enabled before you can work with WSL successfully. So, I’m just going to wait for this to finish downloading, and then we’re going to continue. After this is the installation complete, it says “Open.” Let me open and see if it is complete.

Enter a new Unix username. So, this is like installing Ubuntu. Just give it a username and then give it a password.

All right, so there we go. We have a new Ubuntu installation on our Windows. For good usability, let me just increase the font. Let’s try 24. There we go; that should be much better. Ctrl+L to clear the screen, and then we can continue from here. So now we have Ubuntu. Let’s just see if there are any updates. I’m going to do apt update.

Could not lock the file, so I need sudo.

— so — is like just rerun what was run last.

So, this is instead of retyping the command again; you can just do that, and it’s going to replace it with the last command. While this is happening, let’s come back here. Since I’m on Ubuntu, as I said, there are two ways in which you can install Ansible. The first way, you can use the package manager. You can just do sudo apt install, and you’ll see that there’s an Ansible that will be installed. But the reason why we do this is so that you can get the latest version of Ansible.

You can also install it via pip if you have Python installed. And to be specific, install Python 3 because that’s what is recent. So, install Python 3 and then install pip, and then install Ansible. If you don’t know how to install pip, there are lots of tutorials online. It is a very simple process. So, I will not cover that. Ctrl+L, you clear the screen. So, you can see we have 87 packages that can be upgraded, but I’m not going to do that now. Ctrl+L to clear the screen. So, if I do what I’m telling you, even if you don’t add the PPA, if I do apt search ansible…

apt search ansible. You can see that there is an Ansible version 2.10, and Ansible core is at 2.12. But currently, the Ansible core that is available is 2.12.15. So, you can see this is really not the latest. That’s why we add the PPA. Let me just copy this again. So, sudo apt update to the apt install software-properties. I don’t know if these are already installed, but I’m just going to do it again. They’re probably not installed already. So, I’m just going to install apt software-properties-common, and then we’re going to add the Repository for the Ansible PPA so that just gives us the PPA with the latest Ansible package. So, if I run that, it’s going to run the APT update, and then it’s going to install this application. This is going to install this package, and then after that, it’s going to add the repository from this PPA of Ansible.

Press enter to accept.

So, it’s installing that now. The PPA has been added. Now let’s try and do apt search ansible again. Let’s see if the version is different. So, you can see here we are getting 2.15. In the previous one, Ansible core 2.12. Now it’s 2.15. So, you can clearly see why you should add the PPA because it’s going to give you the latest version of Ansible core and Ansible. Ansible core is the original Ansible. That is the Ansible brain. It has everything with Ansible. It has the inner workings of Ansible. Now, Ansible is a compilation of plugins, modules, basically almost everything you need to run any environment you need to automate. That’s why you install Ansible. It contains Ansible core. So, this is the inner working of Ansible, but Ansible comes with Ansible core and a bunch of other plugins and modules that are going to be instrumental in your automation. So, once you do this, once we know that we’ve added the PPA, we do install ansible. So, if you want to follow along with me in this setup, if you are not on Windows, what you can do is sudo apt install ansible. What you can do is just create a virtual environment and then install Ansible. You can use VirtualBox if that’s the one you want to use. Install VirtualBox. If you’re on Windows, you don’t need any of that. All you need is WSL. Enable WSL, install Ubuntu, and that’s it. So now, let’s just wait for Ansible to install, and we’re going to see the version of Ansible that is installed. If you prefer to go with the Ansible PIP route, there are certain things that will be different, just the location of videos of certain files, but that is really not important because most of the files we’re going to use, we’re going to create them. For example, the host file, that is the inventory file, we’re going to create that. There’s a default base for that, but when we get to that point, I’m going to tell you more about it. For now, we just know that Ansible is installed. You can check the Ansible version. All right, there we go. Ansible is now installed in Ubuntu 20.04. And if we do ansible –version, I think I copied it.

Right-click, edit, and we’ll paste it. On WSL, our Ansible core is 2.15. So there we go; we have Ansible installed successfully, and it’s telling us Python. We’re using Python version 3. Ginger, this is a templating engine that is used in Ansible. So this is a templating engine; it’s used in Jinja. If you install Ansible via Python, some of these locations are going to be different, especially the executable location will be inside of Python if you install it via pip. This has been kind of a long video, slightly long video, but sometimes in tech, it’s very important to understand the theory of things and why we do what we do. In this case, for example, you saw why we add the PPA and also other ways of installing it, even though we only installed it in WSL. So, I did go through a few theoretical things that I know will help you understand something if you had questions about why we do this, we do that. Maybe some of those questions were answered in this video. That’s how to install Ansible. Let’s just confirm what you’re going to do in the next part. We’re going to talk about Ansible configuration. So that’s the next part, Ansible configurations.

Comment Here

Join this free course:

How to host multiple WordPress
websites on a VPS

Close me!