The Wayback Machine - https://web.archive.org/web/20240703134809/https://www.geeksforgeeks.org/ansible/
Open In App

Ansible

Last Updated : 16 Nov, 2023
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).
 



Similar Reads

Ansible vs Ansible Core
The landscape of DevOps and automation is highly dynamic, with Ansible being among the tools that have been developed for configuration management, application deployment and IT orchestration. Nonetheless, within the realm of Ansible, there are two distinct entities called “Ansible” and “Ansible Core”, each having its own weightage and functionalit
9 min read
Difference between Ansible and Puppet
Ansible : It is an effective device for automation to the provision of the goal surroundings and to then set up the application. It follows an easy setup method and does no longer rely on any extra software, servers or client daemons. It is primarily used as a DevOps tool and can operate a lot of duties that in any other case are time-consuming, co
2 min read
Using Ansible to Manage Remote Machines
Ansible is an automation tool used for common IT tasks such as configuring remote machines or container orchestration, continuous deployment, etc. In this article, we are going to use Ansible to configure multiple remote machines using a master or control node( machine which manages or pushes tasks to these remote machines to execute). Before start
4 min read
Introduction to Ansible and its Architecture components
In this article, we will discuss the overview of ansible and will mainly focus on its architecture part. Let's discuss it one by one. Overview :Ansible is an IT automation engine that can automate various IT needs. And it has features like application deployment that means you can deploy your application easily as per your requirements, cloud provi
3 min read
Difference Between Saltstack and Ansible
Pre-requisite: Ansible Both Saltstack and Ansible are used for configuration management and IT automation and are open sources. Though, SaltStack is a new tool in the field still it is efficient, easy to use and scalable Let's see what aspects they differ in. SaltstackSaltstack is an open-source software for IT automation. This software is Python-b
3 min read
How To Run Ansible?
Did you know that there are over 2.8 million applications available in the play store (as of September 2019)? With the rise in the number of applications being deployed or a number of software being built and the continuous rise in demand of companies and individuals for high availability of services, it is difficult to make a stable, reliable, and
3 min read
What is Ansible Vault?
Pre-requisite: Ansible Ansible is a configuration management, deployment, and orchestration tool. It is an open source and provides large productivity to a high amount of automation challenges. It is compatible with every operating system and the host server or cloud. Ansible is accessible to everyone; anyone can use this tool anytime. Ansible is l
2 min read
Difference Between Terraform Vs Ansible
Pre-requisite: Terraform and Ansible Tools like Terraform and Ansible have gained popularity as businesses continue to adopt infrastructure as code (IaC) techniques and embrace cloud computing. Both tools serve similar purposes, but they take different techniques and have other functionalities. Ansible is a powerful automation engine that makes con
6 min read
Ansible Tower
In this article, we will delve into the key features and benefits of Ansible Tower, exploring how it addresses the challenges of modern IT operations. From configuration management and application deployment to dynamic inventory management and compliance auditing, Ansible Tower offers a comprehensive solution for organizations seeking to enhance ef
12 min read
A Brief Introduction To Ansible Roles For Linux System Administration
Ansible is a powerful open-source automation tool and after its origin, it has made the management of system administration very simple and effective. One of Ansible's main features is its use of roles which adds structure and reusability to configuration management. In this article, we'll learn about Ansible roles, covering history, advantages, di
6 min read
Article Tags :