Installing Ansible: A Step-by-Step Guide

Ansible is a powerful open-source tool for IT automation, allowing you to manage configurations, deploy applications, and orchestrate complex workflows. This article provides a comprehensive guide to installing Ansible on various operating systems, ensuring you can get started with automating your IT infrastructure efficiently.

Prerequisites

Before installing Ansible, ensure you have the following prerequisites:

  • A supported operating system (Linux, macOS, or Windows with WSL)
  • Python 3.6 or later (for some distributions, Python 2.7 is still supported but not recommended)
  • Access to an internet connection to download Ansible packages

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