How to Install/Deploy Ansible on CentOS 7



Ansible is powerful automation and configuration management tool written in python. Ansible does by default communicate with machines over the SSH protocol, Ansible is agent free, does not require any additional agent/daemons to be installed on remote machines. You will have to setup playbook to execute multiple commands for a deployment/configuration written in YAML format.

Ansible upholds four months short release cycles to tackle all minor bugs. Major bugs will still have maintenance releases whenever needed.


Prerequisites :            Ansible can be run from any machine with Python 2.6 or 2.7
Operating System:    RHELx, CentOS, Fedora, Debian, Ubuntu and BSD.

Nodes:        ansible-master        ansible-peer1        ansible-peer2        ansible-peer3

Step #1: Add the EPEL Repository

Ansible is part of EPEL community repository for non-standard packages, we need to first setup the EPEL repository om CentOS7.


Once EPEL repo installation is completed, run  makecache command to  download all the metadata for the enabled yum repos.

  • yum makecache

yum update

Step #2: Update OS

Running yum update on all nodes to ensure all installed packages are up to date. While updating packages, yum will ensure that all dependencies are also installed.

  • yum update -y


Step #3 : ssh key deployment across all hosts

Generate authentication keys for ssh using ssh-keygen. -t option reflects the type of key to be generated rsa/dsa/ecdsa.

 [root@ansible-master ~]# ssh-keygen -t dsassh_key_deployment

ssh-copy-id command logs into the remote machine with password to enable key based authentication.

  • [root@ansible-master ~]# ssh-copy-id -i .ssh/ ansible-master

deploy ssh key

 Step #4 : Add all nodes into /etc/hosts

Edit the /etc/hosts file, This file is a simple text file containing IP addresses with hostnames, one line per IP address.


Step #5 : Installing Ansible

While making ansible installation with yum, it does resolve all dependencies of python

  • [root@ansible-master ~]# yum install ansible -y

Ansible Installation

Step #6 : How to Check Ansible version

[root@ansible-master ~]# ansible –version


Step #7 : Add remote host in Ansible inventory (/etc/ansible/hosts) file. 

Edit the /etc/ansible/hosts file to declare the nodes or servers inventory of Ansible.


The format for /etc/ansible/hosts file is an INI-like format. Object mentioned in brackets are group names, deciding what systems you are controlling for what objective.

it’s fine to define hosts in more than one group, for instance a server part of both a webservers and a dbservers


 Step #8 :  Run the commands from Ansible.

[root@ansible-master ~]# ansible all -a “/bin/echo hello”

check host connection

[root@ansible-master ~]# ansible -m ping dbservers,application


 [root@ansible-master ~]# ansible -m command -a ‘uptime’ dbservers,application


[root@ansible-master ~]# ansible -m command -a ‘cat /etc/redhat-release’ dbservers,application



Please share/subscribe if you like this post.

This entry was posted in Linux course online, Linux Learning, Red Hat Linux. Bookmark the permalink.

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Copyright © 2015 Spring Systems. All rights reserved.