G
GuideDevOps
Lesson 2 of 14

Installing Ansible

Part of the Ansible tutorial series.

Prerequisites

Ansible has a beautiful architectural advantage: Agentless architecture.

This means you only need to install Ansible on one machine (your laptop, a bastion host, or a CI/CD server). This machine is called the Control Node.

The servers you want to manage (the Managed Nodes) do not need Ansible installed. They only need:

  1. An SSH connection from the Control Node.
  2. Python installed (Python 3 is standard).

Note: Windows cannot be used as an Ansible Control Node natively. You must use WSL (Windows Subsystem for Linux), a Linux VM, or a Mac.


Installing on Ubuntu / Debian

The easiest way to get the latest version on Debian-based systems is via the official PPA (Personal Package Archive):

# 1. Update your system
sudo apt update
 
# 2. Install properties-common if you don't have it
sudo apt install software-properties-common
 
# 3. Add the Ansible PPA
sudo add-apt-repository --yes --update ppa:ansible/ansible
 
# 4. Install Ansible
sudo apt install ansible

Installing on MacOS

On a Mac, the absolute simplest method is using Homebrew.

brew install ansible

Installing via Python (PIP)

Because Ansible is written in Python, you can install it using pip on any system that has Python installed. This is often the preferred method if you want a specific version of Ansible or if you want to avoid altering system-level packages (by using virtual environments).

# Install for the current user
python3 -m pip install --user ansible

If you only need ansible-core (a stripped-down version without the massive collection of community modules), you can run:

python3 -m pip install --user ansible-core

Verifying the Installation

Open your terminal and type:

ansible --version

You should see output detailing the version of Ansible, the configuration file location, and the Python version it is using:

ansible [core 2.16.2]
  config file = None
  configured module search path = ['/home/ubuntu/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3/dist-packages/ansible
  ansible collection location = /home/ubuntu/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0]

IDE Setup (Highly Recommended)

You will be writing a lot of YAML files. You need an editor that understands YAML indentation and Ansible syntax.

If you are using Visual Studio Code (VS Code), follow these steps:

  1. Open the Extensions pane.
  2. Search for the official Ansible extension (by Red Hat) and install it.
  3. This extension provides:
    • Syntax highlighting specific to Ansible playbooks.
    • Auto-completion for module names and parameters.
    • Hover documentation (hover over a module to see what it does).
    • Integration with ansible-lint to catch bad practices before you run your code.