How Install and Configure Ansible on CentOS 7


Ansible is an open source automation platform. Ansible helps us in configuration management, application deployment, task automation and IT orchestration. Imagine having a number of machines running on the same version of the same operating system, and you want to install a LAMP server on every machine. With ansible you don’t have to install individually on each one. You can install LAMP on every machine using a control machine on which ansible is installed. Ansible is agentless, so you don’t have to install any additional software package on client machines.

Here I will show you how to install and configure ansible on centos 7, which you can use as your control machine.

To get Ansible for CentOS 7, first you have to install epel repository:

#yum install epel-release

Install Ansible:

#yum install ansible

Ansible keeps track of all of the servers that it knows about through a hosts file.

#vi /etc/ansible/hosts

Add the following entries:


node1 ansible_ssh_host=ip_addr

node2 ansible_ssh_host=ip_addr

group_name is to identify all the servers under it together.

My hosts file is given below:

I added only one host (spotfixcrew) under the group (sfcgroup).

For managing hosts through ansible you must have ssh access to them. While connecting with ssh you should not be prompted for a password. So you have to setup a ssh key based authentication with all of the hosts.

Then you have to specify to ansible to which user on the client it should try to connect. Here I use the name ‘prince’.

Create a directory in the ansible configuration structure to specify the group variables.

#mkdir /etc/ansible/group_vars

Now within this directory you can create YAML files for each group you want to configure:

#vi /etc/ansible/group_vars/sfcgroup

My entry in this file is shown below, you have to enter the username through which you can ssh into the host. A YAML file always start with three hyphens (it is important).

Now that you have your hosts set up and enough configuration details to allow you to successfully connect to our hosts, let’s check the connection using ansible ping module.

Ping all of the servers you configured by typing:

#ansible -m ping all

Ping a particular group of servers you configured by typing:

#ansible -m ping sfcgroup

(My group name is sfcgroup, use your group name to ping)

Ping to one of the server you configured by typing:

#ansible -m ping spotfixcrew

(‘spotfixcrew’ is my hostname.)

The output to the above three commands is given below:

Leave a Reply

Your email address will not be published. Required fields are marked *