Ansible Installation
1. Installing Ansible on Linux
Using a Package Manager (Recommended)
For most Linux distributions, Ansible can be installed using the default package manager.
Debian/Ubuntu:
- Update your package manager:
sudo apt update - Install Ansible:
sudo apt install ansible -y
CentOS/RHEL (8+):
- Enable the EPEL repository:
sudo dnf install epel-release -y - Install Ansible:
sudo dnf install ansible -y
Fedora:
- Install Ansible directly using DNF:
sudo dnf install ansible -y
Arch Linux:
- Install Ansible using Pacman:
sudo pacman -S ansible
2. Installing Ansible on macOS
Using Homebrew (Recommended):
- Install Homebrew if you haven’t already:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" - 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:
- Enable WSL:
wsl --install - Install Ubuntu from the Microsoft Store.
Set Up Ansible on WSL:
- Update the package manager:
sudo apt update - 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:
- Install
virtualenv:sudo apt install python3-virtualenv -y # For Debian/Ubuntu - Create a virtual environment:
virtualenv venv - Activate the virtual environment:
source venv/bin/activate - 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:
- Clone the Ansible repository:
git clone https://github.com/ansible/ansible.git
cd ansible - Set up the environment and dependencies:
sudo apt install python3-pip -y
pip install -r requirements.txt - 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.