Introduction

Ansible is an agentless automation tool — you only install it on the control node (the machine that runs playbooks). Target machines need only SSH (Linux/macOS) or WinRM (Windows). This guide covers every major platform: Ubuntu/Debian, RHEL/CentOS/Rocky, Fedora, macOS, and Windows (via WSL). Choose the method that fits your environment.

Quick Install (All Platforms)

# The universal method — works everywhere Python 3.10+ is available
pip install ansible

# Verify
ansible --version

Prerequisites

Requirement        | Minimum  | Recommended
───────────────────|──────────|────────────
Python             | 3.10     | 3.12+
pip                | 21.0     | Latest
SSH client         | Any      | OpenSSH 8+
OS (control node)  | Linux, macOS, WSL | Ubuntu 24.04 LTS

Note: Ansible runs on the control node only. Managed hosts just need Python 3.9+ and SSH.

Ubuntu / Debian

# Install Python and pip
sudo apt update
sudo apt install -y python3 python3-pip python3-venv

# Create a virtual environment (recommended)
python3 -m venv ~/ansible-venv
source ~/ansible-venv/bin/activate

# Install Ansible
pip install ansible

# Verify installation
ansible --version
# ansible [core 2.18.x]
#   python version = 3.12.x

Method 2: APT Package Manager

# Add the official Ansible PPA (Ubuntu)
sudo apt update
sudo apt install -y software-properties-common
sudo add-apt-repository --yes --update ppa:ansible/ansible

# Install
sudo apt install -y ansible

# Verify
ansible --version

Method 3: pipx (Isolated Install)

# Install pipx
sudo apt install -y pipx
pipx ensurepath

# Install Ansible in isolated environment
pipx install ansible

# Verify
ansible --version

Ubuntu 24.04 Specific Notes

# Ubuntu 24.04 enforces PEP 668 — pip install outside venv is blocked
# You'll see: "error: externally-managed-environment"
# Solution: Use a virtual environment (Method 1) or pipx (Method 3)

# If you must use system pip (not recommended):
pip install ansible --break-system-packages

RHEL / CentOS / Rocky / AlmaLinux

# Install Python
sudo dnf install -y python3 python3-pip

# Virtual environment
python3 -m venv ~/ansible-venv
source ~/ansible-venv/bin/activate

# Install
pip install ansible

# Verify
ansible --version

Method 2: DNF Package Manager

# RHEL 9 — enable the Ansible repository
sudo subscription-manager repos --enable ansible-automation-platform-2.5-for-rhel-9-x86_64-rpms
sudo dnf install -y ansible-core

# Rocky/AlmaLinux 9
sudo dnf install -y epel-release
sudo dnf install -y ansible-core

# CentOS Stream 9
sudo dnf install -y epel-release
sudo dnf install -y ansible-core

# Verify
ansible --version

Fedora

# Fedora includes Ansible in the default repos
sudo dnf install -y ansible

# Or for just ansible-core (smaller)
sudo dnf install -y ansible-core

# Or via pip for the latest version
python3 -m venv ~/ansible-venv
source ~/ansible-venv/bin/activate
pip install ansible

# Verify
ansible --version

macOS

# Install Homebrew if not already installed
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

# Install Ansible
brew install ansible

# Verify
ansible --version

Method 2: pip

# macOS ships with Python 3 (or install via Homebrew)
brew install python3

# Virtual environment
python3 -m venv ~/ansible-venv
source ~/ansible-venv/bin/activate

# Install
pip install ansible

# Verify
ansible --version

Windows (via WSL)

Ansible doesn't run natively on Windows — use Windows Subsystem for Linux (WSL).

# Step 1: Install WSL (PowerShell as Administrator)
wsl --install

# Step 2: Restart your computer

# Step 3: Open Ubuntu from Start Menu (or your chosen distro)
# Inside WSL (Ubuntu):
sudo apt update
sudo apt install -y python3 python3-pip python3-venv

python3 -m venv ~/ansible-venv
source ~/ansible-venv/bin/activate

pip install ansible

# Verify
ansible --version

# You can now manage Windows hosts via WinRM or Linux hosts via SSH

Windows Host (Managed Node) Setup

# On the Windows machine you want to MANAGE with Ansible:
# Run in PowerShell as Administrator

# Enable WinRM
winrm quickconfig -q

# Set up basic auth (for testing)
Set-Item -Path WSMan:\localhost\Service\Auth\Basic -Value $true
Set-Item -Path WSMan:\localhost\Service\AllowUnencrypted -Value $true

# For production, use certificate-based or Kerberos auth

Verify Installation

# Check version
ansible --version

# Check Python path
ansible --version | grep python

# Test localhost connectivity
ansible localhost -m ping
# localhost | SUCCESS => {
#     "changed": false,
#     "ping": "pong"
# }

# Test a remote host (replace with your host)
ansible all -i "192.168.1.100," -m ping -u your_user --ask-pass

# List installed collections
ansible-galaxy collection list

# Check configuration
ansible-config dump --changed

Install Specific Versions

# Install a specific version
pip install ansible==10.0.0

# Install ansible-core only (no collections)
pip install ansible-core==2.18.0

# Upgrade to latest
pip install --upgrade ansible

# Install from requirements file
cat > requirements.txt << 'EOF'
ansible>=10.0.0
ansible-lint>=25.0.0
molecule>=25.0.0
EOF
pip install -r requirements.txt

Install Additional Collections

# After installing Ansible, add collections you need:

# Windows management
ansible-galaxy collection install ansible.windows community.windows

# Cloud providers
ansible-galaxy collection install amazon.aws azure.azcollection google.cloud

# Network
ansible-galaxy collection install cisco.ios arista.eos junipernetworks.junos

# Containers
ansible-galaxy collection install community.docker kubernetes.core

# From a requirements file
cat > collections/requirements.yml << 'EOF'
collections:
  - name: ansible.windows
    version: ">=2.0.0"
  - name: community.postgresql
    version: ">=3.0.0"
  - name: community.docker
EOF
ansible-galaxy collection install -r collections/requirements.yml

Common Mistakes

# ❌ MISTAKE 1: Installing Ansible ON a managed host
# Ansible only needs to be on the CONTROL NODE
# Managed hosts need only Python 3.9+ and SSH (or WinRM for Windows)

# ❌ MISTAKE 2: Using system pip on modern distros
pip install ansible
# Error: "externally-managed-environment" (Ubuntu 24.04+, Fedora 38+)
# FIX: Use a virtual environment or pipx

# ❌ MISTAKE 3: ansible vs ansible-core confusion
# "ansible" = ansible-core + community collections (~50 collections)
# "ansible-core" = just the engine, no extra collections
# For most users: pip install ansible (the full package)

# ❌ MISTAKE 4: Mixing pip and apt installs
# Don't install via both pip AND apt — they'll conflict
# Pick one method and stick with it

# ❌ MISTAKE 5: Forgetting to activate venv
source ~/ansible-venv/bin/activate  # Run this first!
ansible --version  # Now it works

Troubleshooting

# "command not found: ansible"
# → Activate your virtual environment or check PATH
export PATH="$HOME/.local/bin:$PATH"

# "No module named ansible"
# → Wrong Python or venv not activated
which python3
which ansible

# pip SSL errors behind corporate proxy
pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org ansible

# Permission denied on install
# DON'T use sudo pip — use a virtual environment instead

# Check which ansible is running
which ansible
ansible --version

Conclusion

The recommended installation method for all platforms is pip install ansible inside a Python virtual environment. This gives you the latest version, avoids system package conflicts, and works identically on Ubuntu, RHEL, macOS, and WSL. After installation, verify with ansible --version and test connectivity with ansible localhost -m ping. Then install any additional collections you need with ansible-galaxy collection install.