Skip to main content

Ansible Installation

1. Installing Ansible on Linux​

For most Linux distributions, Ansible can be installed using the default package manager.

Debian/Ubuntu:​

  1. Update your package manager:
    sudo apt update
  2. Install Ansible:
    sudo apt install ansible -y

CentOS/RHEL (8+):​

  1. Enable the EPEL repository:
    sudo dnf install epel-release -y
  2. Install Ansible:
    sudo dnf install ansible -y

Fedora:​

  1. Install Ansible directly using DNF:
    sudo dnf install ansible -y

Arch Linux:​

  1. Install Ansible using Pacman:
    sudo pacman -S ansible

2. Installing Ansible on macOS​

  1. Install Homebrew if you haven’t already:
    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  2. Install Ansible:
    brew install ansible

3. Installing Ansible on Windows​

To use Ansible on Windows, it’s recommended to install Windows Subsystem for Linux (WSL) and run Ansible from a Linux environment.

Install WSL and Ubuntu:​

  1. Enable WSL:
    wsl --install
  2. Install Ubuntu from the Microsoft Store.

Set Up Ansible on WSL:​

  1. Update the package manager:
    sudo apt update
  2. Install Ansible:
    sudo apt install ansible -y

4. Installing Ansible in a Virtual Environment​

Installing Ansible in a virtual environment provides more control and isolation from your system’s packages.

Steps:​

  1. Install virtualenv:
    sudo apt install python3-virtualenv -y   # For Debian/Ubuntu
  2. Create a virtual environment:
    virtualenv venv
  3. Activate the virtual environment:
    source venv/bin/activate
  4. Install Ansible within the virtual environment:
    pip install ansible

5. Installing Ansible from Source​

You can also install the latest Ansible version directly from its source code:

Steps:​

  1. Clone the Ansible repository:
    git clone https://github.com/ansible/ansible.git
    cd ansible
  2. Set up the environment and dependencies:
    sudo apt install python3-pip -y
    pip install -r requirements.txt
  3. Build Ansible:
    source hacking/env-setup

6. Verifying the Installation​

Once installed, verify that Ansible is correctly set up by running:

ansible --version

This command will display the version of Ansible and other relevant details, confirming a successful installation.


With Ansible now installed, you are ready to start automating infrastructure tasks by creating and executing playbooks.