Ansible Tutorial – An Advanced Overview of Ansible

What is Ansible?

Ansible is simple open source IT tool which automates application deployment, intra service orchestration, cloud provisioning and many other IT services. Ansible is a tool to manage systems and their configuration. It’s a simple  and agentless automation tool. Ansible can manage powerful automation tasks, and can adapt to many different workflows and environments.

Ansible uses playbook to describe automation jobs, and playbook uses very simple language i.e. YAML (It’s a human-readable data serialization language) which is very easy for humans to understand, read and write. So advantage is, even the IT infrastructure support guys can read and understand the playbook and debug if needed.

Ansible Concepts and Architecture

There are two types of machines in the Ansible architecture.

  • Control Nodes
  • Managed Hosts

Control Node

Ansible is simple to install. The Ansible software only needs to be installed on the control node (or nodes) from which Ansible will be run. This machine also has copies of your Ansible project files. A control node could be an administrator’s laptop, a system shared by a number of administrators. The control node should be a Linux or UNIX system. Microsoft Windows is not supported as a control node, although Windows systems can be managed hosts.

Python 2 (version 2.7) or Python 3 (versions 3.5 and higher) needs to be installed on the control node. This includes Red Hat, Debian, CentOS, macOS, any of the BSDs, and so on.

ansible hosts and control node

Managed Hosts

One of the benefits of Ansible is that managed hosts do not need to have a special agent installed. Managed hosts are listed in an inventory, which also organizes those systems into groups for easier collective management. The inventory can be defined in a static text file, or dynamically determined by scripts that get information from external sources.

Linux and UNIX managed hosts need to have Python 2 (version 2.4 or later) installed for most modules to work.

How Ansible Works?

Ansible works by connecting to your nodes and pushing small programs called ansible modules. Then Ansible executes these modules over SSH by default and removes them once finished. Your library of modules can reside on any machine so no need of servers, daemons, or databases.

The management node is the controlling node which controls the entire execution of the playbooks. It’s the node from which you are running the installation and managing configuration. The inventory file provides the list of managed hosts where the Ansible modules needs to run and the management node does a SSH connection and executes the small modules on the managed hosts machine and installs the software.

Ansible architecture

Beauty of Ansible is that it removes the modules once those are installed. The best feature it has, it connects effectively to host machine through ssh and executes the instructions and if the software is already installed then it won’t execute the code to install that software on the host machine.

Host Inventory File

The inventory file contains a collection of hosts that Ansible will manage. These hosts can also be assigned to groups, which can be managed collectively. Groups can contain child groups, and hosts can be members of multiple groups. The inventory can also set variables that apply to the hosts and groups that it defines.

Host inventories can be defined in two different ways.

Static Inventory

A static inventory file is an text file that specifies the managed hosts that Ansible targets. A static inventory is a list of host names or IP addresses of managed hosts.

web.example.com
db.example.com
192.0.2.30

[webservers]
web.example.com
192.0.2.30
[db-servers]
db.example.com

# You can create Standard Sample Inventory as follows:

#File name: hosts
#Description: Inventory file for your application. Defines machine type X node to deploy specific artifacts.
#Defines machine type Y node to upload metadata.

[X-node]
#server1   ansible_host=<target machine for DU deployment>  ansible_user=<Ansible-user> ansible_connection=ssh

web ansible_host=server1.company.com ansible_user=ansadmin ansible_connection=ssh

[Y-node]
#server2 ansible_host=<target machine for artifact upload> ansible_user=<Ansible user> ansible_connection=ssh

server2 ansible_host=server2.company.com ansible_user=admin ansible_connection=winrm

Dynamic Inventory

Ansible inventory information can also be generated dynamically, using information provided by external databases. Opensource community has written multiple sample dynamic inventory scripts that are available on internet. If those scripts don’t meet your needs, you can modify them according to your requirements.

Conclusion

So far you have got deep understanding of Ansible and it’s component. In our upcoming tutorials you will learn more in Ansible.

See More : An Overview of Git – Core Concepts of Distributed Version Control System

Share on:

Ravindra Kumar

Hi, This is Ravindra. I am founder of TheCodeCloud. I am AWS Certified Solutions Architect Associate & Certified in Oracle Cloud as well. I am DevOps and Data Science Enthusiast.

Recommended Reading..

1 thought on “Ansible Tutorial – An Advanced Overview of Ansible”

Leave a Comment