DEV Community

Cover image for Day-8: Install Ansible | 100 Days of DevOps
M. Oly Mahmud
M. Oly Mahmud

Posted on

Day-8: Install Ansible | 100 Days of DevOps

In this guide, we’ll walk through the different ways to install Ansible and get it running on your system. By the end, you’ll be able to execute Ansible commands globally from your terminal.

What is Ansible?

Ansible is an open-source automation engine that helps manage systems, deploy applications, and orchestrate workflows. Unlike many other configuration management tools, Ansible doesn’t require installing agents on managed nodes. It only needs SSH access and Python on the target machine, which keeps things lightweight and secure.

Installation Options

There are several ways to install Ansible:

  1. Package Manager – Install via apt (Debian/Ubuntu), dnf or yum (RHEL/CentOS/Fedora).
  2. Pip (Python package manager) – Install via pip3, which gives you more control over the version.
  3. From Source – Clone the official Ansible GitHub repository.

In this article, we’ll focus on the pip3 installation method since it allows us to install a specific version and ensures portability across environments.

Step 1: Install Python and Pip

Ansible requires Python 3. Most modern Linux distributions come with Python pre-installed. If not, install Python and pip3:

sudo apt update -y
sudo apt install -y python3 python3-pip
Enter fullscreen mode Exit fullscreen mode

You can verify the installation with:

python3 --version
pip3 --version
Enter fullscreen mode Exit fullscreen mode

Step 2: Install Ansible via pip3

To install the latest version of Ansible globally, run:

sudo pip3 install ansible
Enter fullscreen mode Exit fullscreen mode

If you want to install a specific version (for example, Ansible 4.9.0), use:

sudo pip3 install ansible==4.9.0 --prefix=/usr/local
Enter fullscreen mode Exit fullscreen mode

The --prefix=/usr/local flag ensures that the binary goes into /usr/local/bin, which is accessible by all users on the system.

Step 3: Verify Installation

After installation, check whether Ansible is installed correctly:

ansible --version
Enter fullscreen mode Exit fullscreen mode

You should see output similar to:

ansible [core 2.11.x]
  config file = None
  ansible python module location = /usr/local/lib/python3.9/dist-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 3.x.x
Enter fullscreen mode Exit fullscreen mode

Step 4: Add Ansible to PATH (if needed)

If the ansible command isn’t found, add /usr/local/bin to your PATH. Create a file under /etc/profile.d/:

echo 'export PATH=$PATH:/usr/local/bin' | sudo tee /etc/profile.d/ansible.sh
sudo chmod +x /etc/profile.d/ansible.sh
Enter fullscreen mode Exit fullscreen mode

Reload the environment:

source /etc/profile
Enter fullscreen mode Exit fullscreen mode

Now Ansible will be available to all users.

Step 5: Test Ansible with a Ping Command

To make sure Ansible can talk to your servers, create an inventory file:

[servers]
192.168.1.10
192.168.1.11
Enter fullscreen mode Exit fullscreen mode

Then run:

ansible -i inventory servers -m ping
Enter fullscreen mode Exit fullscreen mode

If everything is set up correctly, you’ll see a “pong” response from each server.

Conclusion

So, we've successfully installed Ansible.

Top comments (0)