
Ansible is an open-source automation tool that simplifies the configuration management of IT systems. It is widely used to automate repetitive tasks and streamline complex deployments. As more organizations shift to DevOps and cloud-based environments, the demand for Ansible installation has increased. In this article, we will walk you through the step-by-step process of how to install Ansible on various platforms.
Introduction to Ansible

Ansible is a powerful automation tool that simplifies IT orchestration, configuration management, and application deployment. It operates over SSH and uses YAML-based configuration files, making it easy to learn and use. Ansible’s agentless architecture eliminates the need for installing agents on remote systems, reducing the complexity and security risks associated with traditional automation tools.
Pre-requisites for Ansible Installation
Before you start installing Ansible, you need to ensure that your system meets the required pre-requisites. Ansible is compatible with various operating systems, including Linux, macOS, and Windows. However, the installation process may differ depending on the platform.
Supported Operating Systems
Ansible is compatible with the following operating systems:
- Red Hat Enterprise Linux (RHEL)
- CentOS
- Fedora
- Debian
- Ubuntu
- macOS
- Windows (with the use of Cygwin or Windows Subsystem for Linux)
Required System Configurations
To install Ansible, you need to ensure that your system meets the following requirements:
- Python 2.7 or later (Python 3.x is recommended)
- SSH client and server
- Access to the internet (for package installation)
- Sudo privileges (for package installation)
Once you have confirmed that your system meets the pre-requisites for Ansible installation, you can proceed to install Ansible using one of the following methods.
Installing Ansible using Package Managers
One of the easiest ways to install Ansible is by using package managers. Package managers are software tools that simplify the installation and management of software packages. Ansible can be installed using package managers such as apt, yum, dnf, homebrew, or MacPorts, depending on your operating system.
Installation on Ubuntu
To install Ansible on Ubuntu, you can use the apt package manager. Open the terminal and enter the following command:
sudo apt update
sudo apt install ansible
Installation on Red Hat/CentOS
To install Ansible on Red Hat/CentOS, you can use the yum or dnf package manager. Open the terminal and enter the following command:
sudo yum install ansible # for CentOS 7 or earlier
sudo dnf install ansible # for CentOS 8 or later
Installation on macOS
To install Ansible on macOS, you can use the homebrew package manager. Open the terminal and enter the following command:
brew install ansible
Installing Ansible from Source
Another way to install Ansible is by downloading the source code and building it manually. This method is recommended if you want to customize the installation or use a specific version of Ansible.
Downloading Source Code
You can download the latest version of Ansible from the official website or GitHub repository. Once you have downloaded the source code, extract it to a directory of your choice.
Building Ansible
Before you can install Ansible from source, you need to build it. Open the terminal and navigate to the extracted directory. Enter the following command to build Ansible:
sudo make
Installing Ansible
Once Ansible is built, you can install it by entering the following command:
sudo make install
After completing the installation, verify that Ansible is properly installed by running the following command:
ansible --version
Congratulations! You have successfully installed Ansible on your system. In the next section, we will discuss how to configure Ansible.
Configuring Ansible
After installing Ansible on your system, you need to configure it to start using it for automation. The following are the basic configuration steps for Ansible:
Setting up Inventory File
The inventory file is a configuration file that contains a list of hosts that Ansible can manage. It defines the IP addresses, hostnames, and groupings of the hosts. The inventory file can be in either INI or YAML format. You can create the inventory file manually or use dynamic inventory scripts to generate it automatically.
Configuring SSH Access
Ansible uses SSH to connect to remote hosts and execute commands. Therefore, you need to ensure that SSH access is properly configured for the hosts you want to manage. You can either use password-based authentication or key-based authentication. Key-based authentication is recommended for security reasons. To configure SSH access, you need to add the SSH key of the Ansible control node to the authorized keys file of the remote hosts.
Setting up Ansible Configuration File
The Ansible configuration file contains global settings that apply to all Ansible commands. It is located at /etc/ansible/ansible.cfg on Linux systems. You can modify the configuration file to customize the behavior of Ansible. Some of the common configurations include setting the inventory file location, specifying the SSH private key file, and enabling verbose output.
Verifying Ansible Installation
After configuring Ansible, you need to verify that it is properly installed and can communicate with the remote hosts. The following are the basic steps for verifying Ansible installation:
Testing Ansible Command-Line Interface
To test the Ansible command-line interface, run the following command:
ansible --version
This command should display the version of Ansible that you installed.
Verifying Connectivity with Hosts
To verify connectivity with hosts, run the following command:
ansible all -m ping
This command sends a ping command to all the hosts in the inventory file. If the hosts are properly configured, you should receive a “pong” response from each host.
Running a Sample Playbook
To test Ansible automation, you can run a sample playbook that performs a simple task on the remote hosts. Create a YAML file with the “.yml” extension and save it in the playbook directory. The playbook file should contain a list of tasks that Ansible will execute on the remote hosts. You can then run the playbook using the following command:
ansible-playbook <playbook-file>.yml
This command runs the tasks specified in the playbook file on the hosts in the inventory file.
In conclusion, installing and configuring Ansible is a straightforward process that can be accomplished by following the steps outlined in this article. By mastering Ansible automation, you can simplify your IT operations, increase productivity, and improve the reliability of your deployments.