fbpx

In this article, we will discuss how to install Ansible on CentOS, one of the most popular Linux distributions used in server environments.

Ansible is a powerful automation tool that can be used to manage configurations, deploy applications, and perform various administrative tasks on remote servers.

Step 1: Update Your System

Before installing Ansible, it is recommended to update your CentOS system to ensure that you have the latest security updates and bug fixes. To do this, open a terminal window and enter the following command:

sudo yum update

This command will update all the packages installed on your system to the latest version available in the CentOS repositories.

Step 2: Install EPEL Repository

Ansible is not available in the default CentOS repositories. Therefore, we need to install the EPEL (Extra Packages for Enterprise Linux) repository, which contains the Ansible package. To install the EPEL repository, run the following command:

sudo yum install epel-release

This command will install the EPEL repository on your CentOS system. After the installation is complete, you can verify that the repository has been added by running the following command:

sudo yum repolist

You should see the EPEL repository listed in the output.

Step 3: Install Ansible on CentOS

Now that we have added the EPEL repository, we can proceed to install Ansible. To do this, run the following command:

sudo yum install ansible
How to install Ansible on CentOS

This command will install Ansible on CentOS system. Once the installation is complete, you can verify that Ansible has been installed correctly by running the following command:

ansible --version

This command will display the version of Ansible installed on your system.

Ansible on CentOS version

Step 4: Configure SSH Access

Ansible communicates with remote servers using SSH. Therefore, we need to ensure that SSH access is properly configured on our CentOS system. To do this, we need to generate an SSH key pair and copy the public key to the remote servers we want to manage.

To generate an SSH key pair, run the following command:

ssh-keygen
Configure SSH Access

This command will generate a public-private key pair in the ~/.ssh directory.

Next, we need to copy the public key to the remote servers we want to manage. To do this, run the following command:

ssh-copy-id user@remote-server

Replace “user” with your username on the remote server and “remote-server” with the IP address or hostname of the remote server.

You will be prompted to enter the password for the remote server. Once you have entered the password, the public key will be copied to the remote server and you will be able to access it without entering a password in the future.

Step 5: Add the new server to the Ansible hosts file

The inventory file is a YAML-formatted file that defines the hosts and groups that Ansible can manage. To add a new server, you need to edit the inventory file and add the details for the new server.

echo server1 ansible_host=server-IP ansible_user=root >> /etc/ansible/hosts

Step 5: Test Ansible on CentOS

Now that we have installed Ansible and configured SSH access, we can test it by running a simple command. For example, we can use the ping module to check if Ansible on CentOS can communicate with the remote servers. To do this, run the following command:

ansible all -m ping

This command will ping all the servers listed in your inventory file. If Ansible on CentOS is able to communicate with the servers, you should see a “pong” response for each server.

server1 | SUCCESS => {
    "changed": false,
    "ping": "pong"
}

Conclusion

In this article, we have discussed how to install Ansible on CentOS, one of the most popular Linux distributions used in server environments. We have also covered the steps required to configure SSH access and test Ansible. Ansible is a powerful automation tool that can simplify and streamline various administrative tasks on remote servers.


0 Comments

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.