How to Install Ansible on CentOS 7

Install Ansible on CentOS 7

In this article, we will have explained the necessary steps to install and configure Ansible on CentOS 7. Before continuing with this tutorial, make sure you are logged in as a user with sudo privileges. All the commands in this tutorial should be run as a non-root user.

Ansible is a free and open source Configuration and automation tool for UNIX like operating system. It is written in python and similar to Chef or Puppet but there is one difference and advantage of Ansible is that we don’t need to install any agent on the nodes. It uses SSH for making communication to its nodes.

In this article we will demonstrate how to install and configure Ansible in CentOS 7 and will try to manage its two nodes:

  • Ansible Server – ansible.idroot.us ( 192.168.43.46 )
  • Ansible Client – 192.168.43.120

Install Ansible on CentOS

Step 1. The first command will update the package lists to ensure you get the latest version and dependencies.

Step 2. Install Anisble on CentOS 7.

Install Anisble using yum command:

Once the installation is completed, check the ansible version:

Step 3. Setup Password less SSH configuration between ansible server and ansible client.

We need to generate ssh keys on ansible server and copy this key to public key on ansible client:

We can use ssh-copy-id command to copy public key from ansible server to ansible clients:

We need to be check our ansible server and ansible clients is working password less or not? We can check as like below:

Step 4. Ansible server configuration to manage ansible client.

You can make inventory of our ansible server and ansible client using ansible server host file. Host file can be find in this path on ansible server /etc/ansible/host:

Step 5. Manage ansible client from ansible server.

Check the connectivity of ‘test-servers’ or ansible clients using ping:

We can check the uptime of our ansible client from ansible server:

Redirecting the output of command to a file. Like below:

Congratulation, you have learned how to install and configure Ansible on CentOS 7. If you have any question, please leave a comment below.