Ansible Setup: Configure Ansible for IT Automation via IaC

Reading Time: 6 minutes

Whether you want to manage configurations of your on-premises or cloud hosted server, Ansible is one of the most reliable tools in its category. It is an open-source, cross-platform automation tool that has revolutionized how IT professionals manage their servers, offering streamlined workflows and improved productivity. As you ramp on this technology, be sure check our informative articles, What is Ansible and What Does it Do? and An Introduction to Ansible Playbooks.

If you want to install and configure Ansible for harnessing its incredible power, this guide will help you navigate the process. This article explores everything you need to do to complete your Ansible setup — and then start managing your server configurations. It walks you through the Ansible setup and configuration instructions for three different operating systems, Ubuntu, Windows, and AlmaLinux. So, dive in and get started!

Overview of Ansible Setup & Configuration

Ansible is an IT automation tool — in the Infrastructure as Code (IaC) software category — intended to facilitate the management of remote servers. Ansible requires Python 2.7 or Python 3.5 or higher to run. Ansible is run from a centralized control node and can manage any server accessible over SSH. Remote servers that are managed by Ansible are called managed nodes.

By default, Ansible communicates with managed nodes using OpenSSH. SSH is not the only communication mechanism Ansible supports. You can run tasks on the control server locally, in a Docker container or even a Windows server. The control node will require Linux to run.

What is IT Automation?

Today, System Administrators and DevOps Engineers must manage complex IT infrastructure in the cloud and across multiple sites. Modern web applications typically consist of an API service, a front-end service, and a database service. Manually managing such complex systems would require a lot of time and would be prone to mistakes.

IT automation uses software to provision IT infrastructure, deploy applications and, to manage services configuration changes. The software you use to fill this role needs to provide a reliable and repeatable way to manage your IT tasks. Ansible’s approach to IT automation centers around the concept of a playbook. You can think of an Ansible playbook as a recipe that describes the steps needed to set up your IT infrastructure, deploy your applications and then configure those services.

Advantages of Ansible

Ansible is very easy to learn and allows you to get up and running with automation more quickly than other tools. Ansible is agentless, so you don’t have to install and maintain an Ansible client on your managed nodes. This dramatically simplifies the management of Ansible updates.

Drawbacks of Ansible

Ansible, of course, is not a perfect tool. If an SSH connection is interrupted partway through a playbook run, that node could end up in a partially configured state. Ansible also has a reputation for being slow and may require additional performance tuning to meet your requirements.

Prerequisites for Ansible Setup

Before we begin working on our Ansible setup, we’ll need root access for the Linux servers being used. Installing Ansible is pretty straightforward. We can get started in the next sections, assuming you have SSH access to the servers along with the following prerequisites established.


  • The Ubuntu 18.04 OS installed on your system or a later version of this OS.
  • Sudo access or root privileges.
  • Internet connectivity to download Ansible packages.
  • Python 2.7 or Python 3.5 or later installed.


  • The Windows Server 2012 OS or higher installed on your system.
  • Administrative privileges to install the software.
  • PowerShell version 3.0 or higher.
  • Python 3.5 or later installed.
  • Internet connectivity to download Ansible packages.


  • The AlmaLinux 8.x OS or higher installed on your system.
  • Sudo access or root privileges.
  • Internet connectivity to download Ansible packages.
  • Python 2.7 or Python 3.5 or later installed.

Ansible Setup — Install & Configure Ansible on Ubuntu

You must follow these steps to install Ansible on your Ubuntu server.

Step #1: Connect to Your Soon-to-Be Ansible Controller

You can make this connection using your favorite Secure Socket Shell (SSH) client. With Ubuntu, you use Terminal to establish a secure connection to your host.

Step #2: Update the Packaging Lists

Any time you are installing new software, it is a good idea to ensure your existing operating system software is up to date. Let's start with that task first.

Use the command below to update the package lists. This command will update the local package lists on your Ubuntu system to ensure that you have the latest information about available software packages:

sudo apt update

Step #3: Install the software-properties-common Package

This step is necessary for managing software repositories. Run the following command to install the software-properties-common package:

sudo apt install software-properties-common

Step #4: Add the Ansible Personal Package Archive (PPA)

It must be added as an apt repository. Run the command below to add it. This command adds the Ansible PPA as a software repository, allowing you to install Ansible through the apt package manager:

sudo apt-add-repository --yes --update ppa:ansible/ansible

Step #5: Install Ansible

Run the following command to install Ansible on your machine:

sudo apt install ansible

Step #6: Verifying Ansible is Installed

After the installation is complete, you need to verify that Ansible is installed by running the following command:

ansible --version

When you run the above command, it will display the version information for Ansible on your Ubuntu system. If Ansible has been installed successfully, you should see the version number along with other details. 

If you don't get this information, then you might have done something wrong along the way. Simply revisit all the steps to ensure they were well executed.

Ansible Setup — Install & Configure Ansible on Windows

Follow these steps to install and configure Ansible on your Windows server.

Step #1: Install Python

First, you must install the latest version of Python. Download the latest version of Python for Windows from the official website.

After downloading Python, run its installer and follow the instructions to complete the installation. As you install Python, remember to check the Add Python checkbox with regard to the PATH environment variable option.

Step #2: Install PIP

Launch the Windows PowerShell tool as an administrator and run the following command. This command will install PIP and also ensure it is added to the PATH environment variable:

python -m ensurepip --default-pip

Step #3: Install Ansible

In the same PowerShell window, you must run the command below to install Ansible using the PIP package:

pip install ansible

The above command will download and install Ansible and all its dependencies. After the installation, you will need to verify if Ansible is properly installed by running the command below:

ansible --version

Step #4: Ansible Setup — Final Configurations

Before using Ansible, you must make a few more configurations to ensure everything is running properly.

  • Start by creating an inventory file and setting up SSH.
  • Create a text file named inventory using a text editor.
  • In the inventory file, list the IP addresses or hostnames of the Windows machines you want to manage, one per line under a group name (for example, [windows]).
  • Save the inventory file in a location you can easily remember.
  • Install an SSH server on the Windows machines you want to manage. OpenSSH is a popular option for Windows. Use the official download link for OpenSSH.
  • Configure the SSH server by editing the sshd_config file located in the installation directory of OpenSSH (usually C:\Program Files\OpenSSH\sshd_config).
  • Uncomment the following line to allow remote access:
  • You should now save the file and restart the OpenSSH service.

Step #5: Test Ansible

To test Ansible, run the following command in PowerShell:

ansible windows -i <path/to/inventory> -m win_ping

Remember to replace with the actual path you chose for your inventory file. Running this command should ping the Windows machines listed in the inventory file and return a success message if everything is set up correctly.

Ansible Setup — Install & Configure Ansible on AlmaLinux

Step #1: Update the System

Start by updating your system to the latest available packages using the command below:

sudo dnf update -y

Step #2: Configure the EPEL Repository

Since Ansible and its dependencies are unavailable in AlmaLinux's default repositories, you need to configure the Extra Packages for Enterprise Linux (EPEL) repository. Use the command below to install the EPEL repository:

sudo dnf install -y epel-release

The above command will add the EPEL repository to your AlmaLinux system, allowing you to access Ansible packages.

Step #3: Install Ansible With the dnf Command

You can install Ansible using the following dnf command:

sudo dnf install ansible -y

Running the above command will install Ansible and its dependencies from the EPEL repository.

Step #4: Verify the Ansible Installation

Finally, you must verify your Ansible installation using the following command:

ansible --version

Running the above command will display the version information for Ansible on your AlmaLinux system, which confirms that the installation was successful.

Wrapping Up

This guide walks through the essential steps for installing and setting up Ansible on various server operating systems, including Ubuntu, Windows, and AlmaLinux. Ensure you have the prerequisites for each OS and carefully follow the provided steps to avoid encountering errors during the installation process. By correctly installing Ansible, you can leverage its capabilities to manage your server configurations effectively.

If you found this guide helpful, you may also check our article about using Ansible in DevOps to learn more about how you can use this tool in DevOps. We’ve only scratched the surface with Ansible so far. All in all, Ansible is an excellent tool you can use to save time, money and effort to automate tasks across a single or multiple remote servers.

Original Publication Date

This article was originally published in August 2020. It has since been updated for accuracy and comprehensiveness.

Avatar for Chika Ibeneme

About the Author: Chika Ibeneme

Chika Ibeneme is a Community Support Agent at The Events Calendar. He received his BA in Computer Science in 2017 from Northern Caribbean University and has over 5 years of technical experience assisting customers and clients. You can find him working on various WordPress and Shopify projects.

Latest Articles

Using a Cloudflare Argo Tunnel with load balancing

Read Article

Subdomain takeover — protect your website against it!

Read Article

Controlling PHP settings with a custom php.ini file

Read Article

Linux dos2unix command syntax — removing hidden Windows characters from files

Read Article

Change cPanel password from WebHost Manager (WHM)

Read Article