Introduction to Ansible | High Level Understanding of Ansible

Last Updated on February 18, 2023 by cscontents

Introduction

Do you want to learn Ansible? If so, you are in the right place. To make it clear & concise, we have written this article in question & answer format, hope it will help you.

What is Ansible?

Ansible is an open-source IT automation tool which is mostly used for configuration management, application deployment etc. It is written in Python language.

If you want to learn Ansible basics then please check out the below course from KodeKloud which offers one of the best learning material in DevOps world.

Link of Training Course: Ansible for absolute beginners

Note: The above links are affiliate links, if you enroll this course using the above link, then it would help us to get some monetary benefit from KodeKloud. It won’t cost you anything.

How to use Ansible?

Ansible is an agent less automation tool which we can use to automate various manual task. For this we need to install Ansible in a machine which will be called as controller machine and from this controller machine we can do various task in remote machines. Here, we don’t need to install any kind of agent in the remote hosts for Ansible to work. Some examples of task are deploying application, configuring web server etc.

How Ansible works?

To understand how exactly Ansible works, you need to look at the architecture of Ansible working model.

Various components in the controller machine.

  • Ansible engine
  • Modules
    • Core Modules – these are the modules which come with Ansible by default
    • Custom Modules – these are the modules which we create if our required module is not present
  • plugins
    • connection plugin – this plugin is used to establish the communication with remote host.
    • Callback plugin – this plugin is used to handle all the outputs.
  • Inventory file – this is a normal text file where we store the details of the remote hosts.
  • Playbook – this is YAML file where we mention the various tasks which need to be performed in the remote host.

In controlled or managed or target host, there is no requirement of installing any kind of agent.

Ansible working model
Ansible Architecture

How Ansible connects with remote host?

Connection with Linux machines

To connect with Linux machines, Ansible uses SSH protocol.

Port requirement

SSH protocol uses port 22.

Connection with Windows machines

To connect with Windows machines, Ansible uses WinRM. WinRM is a piece of software/client written in python language which need to be installed on Ansible controller machine/node. And WinRM uses WS-Management protocol.

Port requirement

By default, Ansible uses port 5986 (HTTPS) while communication using WinRM. If we want to go with HTTP, then we need to specifically mention ansible_port: 5985

How Ansible perform various tasks in multiple remote host – sequential or parallel?

By default, Ansible runs the tasks parallelly in the servers. For example, if there are 10 remote servers and then Ansible will perform the tasks at the same time in all the 10 remote servers.

Let’s say there are total 6 tasks to be performed in all remote servers.

Task 1 → Task 2 → Task 3 → …… → Task 6

Now, by default, Ansible will start running the Task 1 in all the 10 servers and wait until in all the servers it is finished. Once Task 1 is finished in all the servers and then only Ansible will start the Task 2 in all the 10 servers and in this way, it will carry on.

In the above case, if any task gets failed in any server, then Ansible will skip that server.

Ansible controller node & managed node requirements

Ansible Controller node:

  • Ansible Controller node must be a Linux machine, we can’t use Windows machine as Ansible controller node.
  • Python must be installed in Ansible controller node.
    • Python 2 >= version 2.7
    • Python 3 >= version 3.5

Ansible Managed node or Target machine

  • It can be Linux or Windows machine
  • Python needs to be installed in the target machines since by default Ansible modules require Python.

 

Thank You.

 

If you are interested in learning DevOps, please have a look at the below articles, which will help you greatly.