How to install Ansible | Ansible tutorial

How to install Ansible | Ansible tutorial

In this tutorial we will learn how to install Ansible. Ansible is an agentless automation tool that you install on a single host (referred to as the control node). I recommend you to read previous article 'Getting Started with Ansible' to understand this tutorial article better.

Ansible is a tool that helps you automate tasks on lots of computers without needing to install anything on those computers. You just install Ansible on one computer, called the control node, and it can control many others, called managed nodes, using simple commands. No fancy setup needed, just simple and easy.

Control node can manage an entire fleet of managed nodes remotely with SSH, Powershell remoting, and numerous other methods, where all from a simple command-line interface with no databases or daemons required.

Requirements:

  1. Control Node: For control node (the machine that runs Ansible), you can use nearly any UNIX-like machine with Python installed. This includes Red Hat, Debian, Ubuntu, macOS, BSDs, and for Windows users, you'll need Linux, whether it's in the form of WSL or a pure Linux OS by switching to Linux because windows without WSL is not supported.
  2. Managed Node: The managed node does not require Ansible to be installed, but requires Python to run Ansible-generated Python code. The managed node also needs a user-account that can connect through SSH to the node with an interactive POSIX shell.

Now let's select an Ansible package and version to install on Control Node

Ansible’s community packages are distributed in two ways:

  1. ansible-core: This is minimal and  contains set of Ansible.Builtin
  2. ansible: This is much larger “batteries included” package, which adds a community-curated selection of Ansible Collections for automating a wide variety of devices.

Choose the package that fits your needs and lets proceed to installiation.

Installing Ansible on Linux/Unix-based Systems

Step 1: Update Package Repository

sudo apt update

Step 2: Install Ansible

sudo apt install ansible

Step 3: Verify Installation

ansible --version

Installing Ansible on macOS

Step 1: Install Homebrew (if not already installed)

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Step 2: Install Ansible

brew install ansible

Step 3: Verify Installation

ansible --version

Installing Ansible on Windows (via WSL)

Step 1: Install Windows Subsystem for Linux (WSL)

  • Follow the official Microsoft documentation: Install WSL

Step 2: Install a Linux Distribution (e.g., Ubuntu) from Microsoft Store

Step 3: Install Ansible on Linux Distribution

  • Follow the steps mentioned for Linux/Unix-based systems.

Step 4: Access Ansible via WSL

Ansible requires Python to be installed on the control node. It is pre-installed on most UNIX-like systems. For Windows, Python may need to be installed separately.

Install using pipx or python-pip

Make sure that you havepython and pipx or pip installed on system, You can use these commands pipx --version or pip --version or pip3 --version to verify pip installation on your system.

Install ansible

pip install ansible or pip insyall anible-core

pip3 insyall anible or pip3 insyall anible-core

pipx install ansible or pipx install ansible-core

So this is how we can install Ansible on our system.

Here is more detailed article on how to install ansible on various destros.