How to Install Ansible on Ubuntu, RHEL, macOS & CentOS
In this post, we will install Ansible across various Operating Systems such as Ubuntu, RHEL, CentOS, MacOS, and Windows.
Installing Ansible with pip
Pip is the Python package installer. Ansible can be installed with pip, which is very straightforward to use and install any other Python package with. This also ensures that all Python dependencies are installed.
#Install python3 and pip on CentOS:
Sudo yum install epel-release
Sudo yum install python3-pip
#Install python3 and pip on RHEL:
sudo dnf install --assumeyes python3-pip
#Install python3 and pip on MacOS:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
brew install python
#Install python3 and pip on Ubuntu:
sudo apt update
sudo apt install python3-pip
#Install python3 and pip on Windows:
Run the Python installer for Windows and select "Add Python 3.x to PATH", this will ensure pip is callable from cmd.
#Validate you have python and pip installed:
Python3 ---version
pip ---version
#Install Ansible using pip:
pip install ansible
#Validate Ansible
Ansible ---version
How to install Ansible on Ubuntu
sudo apt update && sudo apt upgrade -y
sudo apt install software-properties-common
sudo add-apt-repository --yes --update ppa:ansible/ansible
#Install Ansible
sudo apt install ansible -y
#Validate Ansible:
ansible ---version
How to install Ansible on RHEL
Red Hat Enterprise Linux (RHEL) is a subscription-based product and provides Ansible as part of its software repository, ensuring enterprise-level stability and support.
To install Ansible on RHEL run:
sudo yum update -y
sudo yum install epel-release
sudo yum install ansible
#Validate Ansible:
ansible ---version
How to install Ansible on Windows OS
Windows is a bit more complex compared to all the Unix-like distributions.
Can Ansible run on Windows?
There is no direct way to make a Windows machine into an Ansible control node. Ansible is designed to run on Unix-like operating systems such as Linux and MacOS. The main reason behind this is that Ansible depends on Python and certain Unix/Linux-specific functionalities like SSH for its operation, which does not natively integrate with Windows in the same manner.
If you have Windows-heavy environment, there are a few workarounds you can utilize in order to make a Windows machine into an Ansible control node. You can use:
Windows Subsystem for Linux (WSL)
Docker for Windows
Virtual Machine
Installation Steps For WSL
Open Powershell as Administrator and run the following to Enable WSL (Windows Subsystem for Linux). This, by default, will install Ubuntu as your Linux distribution.
wsl --install
Once you have the Linux distribution installed, you will be prompted to create a user account and password.
After this, you should now be able to run commands on your WSL Linux Box.
In this example, we installed the Ubuntu Linux distribution and ran the following to install Ansible:sudo apt update && sudo apt upgrade -y sudo apt install ansible -y #Validate Ansible installation ansible --version