How to Install Ansible on Centos 7: Step-By-Step Guide

How to Install Ansible on Centos 7: Step-By-Step Guide

Ever heard of Ansible? It’s this fantastic open-source automation tool that makes managing IT stuff a breeze. You can automate setting up, deploying, and organizing systems like a pro.

Ready to get started? Awesome! We’re going to guide you through installing Ansible on your CentOS 7 machine. Soon, you’ll be automating server tasks like a champ.


But before we jump in, make sure you’ve got these bases covered:

  1. CentOS 7 Server: You’ll need one of these with either root access or a user who can use sudo powers.
  2. Internet Connection: Yup, you’ll need this to grab some packages from the web. It’s like having a map to the treasure!

Step 1: Update System Packages

First, it is important to update your system packages to ensure you have the latest updates and security patches. Open a terminal or connect to your CentOS 7 server via SSH and execute the following command:

sudo yum update -y

Step 2: Install EPEL Repository

Ansible is not available in the default CentOS 7 repositories. We need to install the Extra Packages for Enterprise Linux (EPEL) repository, which provides additional packages. Run the following command to install the EPEL repository:

sudo yum install epel-release -y

Step 3: Install Ansible

Once the EPEL repository is installed, we can proceed to install Ansible itself. Execute the following command:

sudo yum install ansible -y

Step 4: Verify Ansible Installation

To verify that Ansible has been installed successfully, run the following command:

ansible --version

You should see output similar to the following:

ansible 2.9.26
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.6/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 3.6.8 (default, Nov 16 2020, 16:55:22) [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)]

Step 5: Configure Ansible Hosts

Ansible uses a hosts file to define the systems it manages. By default, the hosts file is located at /etc/ansible/hosts. Open the file using a text editor:

sudo nano /etc/ansible/hosts

You can add the IP addresses or hostnames of the servers you want to manage. For example:


Save the file and exit the text editor.

Step 6: Test Ansible Connection

Now, let’s test the connection to the managed hosts. Run the following command:

ansible all -m ping

If the connection is successful, you will see output similar to the following: | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    "changed": false,
    "ping": "pong"
} | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    "changed": false,
    "ping": "pong"