Open In App

Ansible

Improve
Improve
Like Article
Like
Save
Share
Report

Ansible is an open-source IT engine that automates application deployment, cloud provisioning, intra-service orchestration, and other IT tools. It is an automation and orchestration tool popular for the following reasons: 

  1. Simple to Install.
  2. Free and open source.
  3. Lightweight and consistent.
  4. OpenSSH security features make it very secure.

What Is Ansible?

Ansible can be used to deploy the software on different servers at a time without human interaction. Ansible can also be used to configure the servers and create user accounts. Ansible is an agent-less software which means there is no need to install the software in the nodes which means you need to do the SSH to connect the nodes to perform the required operations on the servers.

Ansible playbooks can be written very easily they will be like plain english and Ansible is developed using Python language. There is no need for any knowledge of programming. A single ansible control node can manage thousands of the nodes.

Ansible Architecture

  1. Control node: Commands and Playbooks can run by invoking /usr/bin/ansible or /usr/bin/ansible-playbook, from any control node. You can use any computer that has Python installed on it as a control node. However, one can not use a computer with Windows OS as a control node. One can have multiple control nodes.
  2. Managed nodes: Also sometimes called “hosts”, Managed nodes are the network devices (and/or servers) you manage with Ansible.
  3. Inventory: Also sometimes called “hostfile”, Inventory is the list of Managed nodes use to organize them. It is also used for creating and nesting groups for easier scaling.
  4. Modules: These are the units of code executed by Ansible. Each module can be used for a specific purpose. One can invoke a single module with a task, or invoke several different modules in a playbook.
  5. Tasks: The units of action in Ansible. One can execute a single task once with an ad-hoc command.

Ansible-architecture

Ansible Playbook With Example

These are the ordered list of tasks that are saved so you can run those tasks in that order repeatedly. Playbooks are written in YAML and are easy to read, write, share and understand.Ansible playbooks can perform wide variety of tasks as mentioned below

  1. Deploying and configuring applications
  2. Managing system configurations
  3. Orchestrating complex workflows

Example

The language used to write the ansible playbooks was YAML which is human redable.Following sections will consists in ansible playbook.

---
- hosts: all
tasks:
- name: Install the Apache web server
apt:
name: apache2
state: present




  1. Hosts: Host in ansible play book defines no.of remote host that playbook will executed and performs the task specified.
  2. Vars: Vars in anisble playbook defines the variables which can be used through out the playbook.
  3. Tasks: This is the section where we are going tot mention the type of task to be executed in the host servers.

Ansible Tower

Ansible tower provides web-based user interface to manage the playbooks which are used to configuring the software’s. Ansible tower will acts as an medium to manage and execute the task like playbooks and adding the new host to the ansible. following are the some features available in the ansible tower.

  1. Security: Ansible tower provides the Role-based access control (RBAC) which can be used to manage the access of users and can assign permissions to the playbooks and other resources. You can make sure the which user should which type permissions to access the resources in the ansible tower.
  2. Job scheduling: Ansible tower provide the option for scheduling the jobs to execute which will execute automatically in the interval’s of time This can help to automate tasks such as daily backups or weekly system updates.

Ansible Modules

Ansible modules are scripts which can be reused and performs the tasks which have mentioned init in the host servers on behalf of you. Instead of performing the installation of softwares manually on each server ansible will automate the process. The tasks which you want to perform can be done on multiple OS also as mentioned following.

  1. Linux
  2. Windows
  3. macOS)

The module which you are going to use will be written in the python. And the modules typically stored in central location which is like git repository they can be reused and shared with others.

Types of Ansible Modules

Following are the some modules which are frequently used in the ansible.

  1. System modules
  2. Application modules
  3. Cloud modules
  4. Networking modules
  5. Command modules

Ansible Roles

Ansible material can be arranged and reused using Ansible roles. They usually include a collection of variables, handlers, tasks, and templates used to carry out a particular activity, like setting up an application or installing and configuring a web server.Ansible playbooks can be made more modular and reusable by using roles. To deploy many web apps, you could, for instance, build a role for installing and configuring the Apache web server and then utilise that role repeatedly in different playbooks.Sharing Ansible material with other people is another way to use roles. To make your roles available for usage in other people’s playbooks, you can publish them to Ansible Galaxy, a public repository for Ansible roles.

Ansible vs Terraform

Ansible

Terraform

Declerative approach it cares about current and end state of the system after executing playbook.

Declerative approach it cares about current and end state of the system after executing script file.

It doesn’t maintain type of statefile to track the task performed in the host servers.

Maintain the statefile and before executing any task it will cross verify with that statefile.

Playbooks for a variety of use cases are simple to find and distribute because to Ansible’s huge community and large library of pre-built modules.

Terraform is a great option for infrastructure provisioning and administration because of its huge ecosystem of providers for various cloud platforms and services.

Flexible, powerful, and easy to use.

Scalable, efficient, and secure.

Ansible Installation

In order to install ansible, the system must have python preinstalled. 
Open up Terminal and execute the following commands.:

1. Add the Ansible Repository.

sudo apt-add-repository -y ppa:ansible/ansible 

Add ansible repository

 2. Update the system repository listings.

sudo apt-get update

update system repos

 3. Install the ansible packages.

sudo apt-get install -y ansible

instal ansibleinstall ansible

FAQs On Ansible

1. What is Copy Module in Ansible?

The “copy” module in Ansible is used to copy files and directories from the local system (the machine where Ansible is run) to remote target hosts.

2. What is Ansible Ping Command?

Ansible ping command is basically used to ping the or check the reachability of the remote host machines.

3. What is Ansible vs Jenkins?

Ansible is an configuration management or automation tool and jenkins is an tool used for CI/CD (Continuous Integration and Continuous Delivery (or Continuous Deployment)

4. What Language is Ansible In?

Ansible is primarily written in Python. Ansible playbooks are written in the YAML (Yet Another Markup Language).
 



Last Updated : 16 Nov, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments