How to Install/Deploy Ansible on CentOS 7

Introduction:

51982

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:

192.168.1.81        ansible-master
192.168.1.82        ansible-peer1
192.168.1.83        ansible-peer2
192.168.1.84        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.

Ansible

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

DevOps

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/id_dsa.pub 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.

etc_hosts

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

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.

 1

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

Adding_Hosts

 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

Ansible_Ping

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

uptime

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

ping_check

 

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.