How to Install Ansible: Complete Guide for All Platforms

Ansible is the leading open-source automation tool for IT infrastructure management, configuration, and application deployment. This comprehensive guide covers Ansible installation on Linux, macOS, and Windows systems, with step-by-step instructions for beginners and advanced users.

Whether you’re a DevOps engineer, system administrator, or IT professional looking to automate your infrastructure, this guide will help you get Ansible up and running quickly.

Why Install Ansible?

Ansible provides:

  • Agentless automation - No software installation on managed nodes
  • Infrastructure as Code - Declarative configuration management
  • Multi-platform support - Linux, Windows, network devices
  • Simple YAML syntax - Easy to learn and maintain
  • Extensive module library - 3000+ built-in modules
  • Enterprise features - RBAC, workflows, and more

Ansible Installation Prerequisites

Before installing Ansible, ensure your system meets these requirements:

System Requirements

  • Operating System: Linux, macOS, or Windows (with WSL)
  • Python Version: Python 3.6+ (Python 2.7 supported but deprecated)
  • Memory: Minimum 512MB RAM (1GB recommended)
  • Disk Space: 100MB free space for installation
  • Network: Internet connection for package downloads

Required Skills

  • Basic command-line knowledge
  • Understanding of package managers (apt, yum, brew, pip)
  • Familiarity with your operating system

Installing Ansible on Linux

Debian-based Systems (Ubuntu, Debian)

  1. Update Your Package Index:

    sudo apt update
    
  2. Install Ansible:

    sudo apt install ansible -y
    
  3. Verify the Installation:

    ansible --version
    

Red Hat-based Systems (RHEL, CentOS, Fedora)

  1. Enable EPEL Repository (for CentOS):

    sudo yum install epel-release -y
    
  2. Install Ansible (for Fedora, RHEL):

    sudo yum install ansible -y
    
  3. Verify the Installation:

    ansible --version
    

Arch-based Systems (Arch Linux, Manjaro)

  1. Install Ansible:

    sudo pacman -S ansible
    
  2. Verify the Installation:

    ansible --version
    

Installing Ansible on macOS

For macOS, Ansible can be installed using Homebrew.

  1. Install Homebrew (if not already installed):

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

    brew install ansible
    
  3. Verify the Installation:

    ansible --version
    

Installing Ansible on Windows

On Windows, Ansible can be installed using the Windows Subsystem for Linux (WSL).

  1. Enable WSL:

    • Open PowerShell as Administrator and run:
      wsl --install
      
  2. Install a Linux Distribution:

    • After enabling WSL, install a Linux distribution from the Microsoft Store (e.g., Ubuntu).
  3. Install Ansible in WSL:

    • Open the installed Linux distribution and follow the installation steps for Debian-based systems mentioned above.

Installing Ansible Using Pip

Alternatively, Ansible can be installed using Python’s package manager, pip. This method works on any operating system with Python installed.

  1. Install pip (if not already installed):

    sudo apt install python3-pip -y  # Debian-based
    sudo yum install python3-pip -y  # Red Hat-based
    
  2. Install Ansible Using pip:

    pip3 install ansible
    
  3. Verify the Installation:

    ansible --version
    

Configuring Ansible

After installing Ansible, a few configuration steps will help you get started with automation:

  1. Set Up the Inventory File:

    • Create a file named hosts (or any preferred name) and list your managed nodes (hosts) in it.
      [webservers]
      server1.example.com
      server2.example.com
      
      [dbservers]
      db1.example.com
      db2.example.com
      
  2. Create an Ansible Configuration File (optional):

    • Create an ansible.cfg file in your project directory to customize Ansible’s behavior.
      [defaults]
      inventory = ./hosts
      remote_user = your_user
      
  3. Test Your Setup:

    • Use the ping module to test connectivity to your managed nodes.
      ansible all -m ping
      

Conclusion

Installing Ansible is a straightforward process that can be accomplished on various operating systems using different methods. Whether you prefer using native package managers, Homebrew, or pip, Ansible’s flexible installation options ensure you can set it up in your preferred environment. By following this guide, you can quickly get started with Ansible and begin automating your IT tasks, improving efficiency, consistency, and reliability across your infrastructure.

For more detailed information and advanced configurations, refer to the official Ansible documentation.

Subscribe to the YouTube channel, Medium, and Website, X (formerly Twitter) to not miss the next episode of the Ansible Pilot.

Academy

Learn the Ansible automation technology with some real-life examples in my Udemy 300+ Lessons Video Course.

BUY the Complete Udemy 300+ Lessons Video Course

My book Ansible By Examples: 200+ Automation Examples For Linux and Windows System Administrator and DevOps

BUY the Complete PDF BOOK to easily Copy and Paste the 250+ Ansible code

Want to keep this project going? Please donate

Patreon Buy me a Pizza