Managing 100 or more servers is a tedious task. So in such situations, we can deploy/use Ansible. Ansible is an open source automation platform.

The main features why it is commonly used are:
1. Simple to setup
2. Efficient and Powerful.

Ansible is mainly used for :
1. Configuration Management.
2. Application deployments.
3. Service Orchestration.

Ansible is free and it mainly runs on MAC, BSD and Linux platforms. It uses OpenSSH as the transport protocol. Ansible scripts, which is commonly known as “Playbooks” are written in YAML (YAML Ain’t Markup Language). Playbook is actually a set of instructions which tells Ansible to what needs to be done, when it actually connects to each machine.

Let me familiarize you with some of the Ansible terminologies.

1. Controller Machine: This is where Ansible is installed and which is responsible for running the provisioning on the servers.
2. Inventory: It contains all the information’s about the servers we are managing.
3. Playbook: It is a set of instruction manual which tells Ansible what to do when it connects to each machine.
4. Task: This is the one which defines a single procedure to be executed.
5. Module: These are single scripts that will be deployed on target hosts.
6. Role: It is a set of tasks and additional files. which is used to configure the host to the server for a certain purpose/roles.
7. Play: Execution of a Playbook is called “Play”.
8. Facts: This contains the information about a system ( Network Interfaces and Operating Systems )
9. Handlers: It is used to notify service status changes.

How to Install Ansible:

  • On CentOS machines:

    # yum install epel-release

    # yum install ansible

  • On Debian

    # apt-get install ansible

Once it is installed, The verification can be done by the following command.
# ansible –version

Once we have Ansible installed, we’ll need to add the remote servers to its configuration file, located in /etc/ansible/hosts:

Configuring Ansible Hosts :

Open the /etc/ansible/hosts file as a root user:

The syntax would be like as mentioned below

alias ansible_ssh_host=server_ip

|| alias is just a name to refer to the server.

Say, if we have 2 servers that we want to control with Ansible.

Since Ansible communicate with client using SSH, all the servers which we need to manage should be accessible from Ansibile server.

Assume the server’s IP address as & We are naming these 2 servers as “host1 & host2”.
Then we need to add these entries to the “/etc/ansible/hosts”

|| [servers]

host1 ansible_ssh_host=
host2 ansible_ssh_host=

Ansible of course will attempt to associate with the remote hosts utilizing the current username thus, we have to refresh ansible that it ought to interface the servers in the gathering “servers” with the client “test”.

  • Create a directory in the Ansible configuration structure called “group_vars”

# mkdir /etc/ansible/group_vars

We can create YAML formatted files for each group within this folder.

# vi /etc/ansible/group_vars/servers

** Note: YAML file starts with “–”

Running playbooks

We are creating a file “basic” in the /tmp directory ( host1 )

# vi basic_playbook.yml

– hosts: host1
– name: Create file
path: /tmp/basic
state: touch

To run Playbooks use the command.

#ansible-playbook <playbook name>

Here it is basic_playbook.yml

This is only a brief note on Ansible and its basic operations.
Hope this would help you all.

[tagline_box backgroundcolor=”description=” shadow=”no” shadowopacity=”0.7″ border=”1px” bordercolor=”” highlightposition=”top” content_alignment=”left” link=”” linktarget=”_self” modal=”” button_size=”” button_shape=”” button_type=”” buttoncolor=”” button=”” title=”” description=”If you have any queries on how to install Ansible And Run Playbook feel free to leave us a message and our representative will get back to you.

” margin_top=”50px” margin_bottom=”” animation_type=”slide” animation_direction=”left” animation_speed=”0.3″ class=”” id=””]