What Is Ansible & How Does It Work?

Ansible tower

What is Ansible?

Ansible can be defined as a software tool developed to provide automation that is not only simple but delivers high-level performance for cross-platform computer support. 

It was initially devised for I.T. professionals for their use for the deployment of applications, workstations and server updates, cloud provisioning, intra-service orchestration, configuration management, and all those things that a systems administrator carries on a weekly or daily basis. Ansible is easy to deploy because it doesn’t depend on the agent software and has no additional security infrastructure.

Since Ansible is wholly related to automation, it must be instructed to accomplish each write-everything down a job and must w in a simple script to simplify version control. The practical result of this is considered a significant contribution to the “infrastructure as code” movement in I.T. It refers to the notion that maintaining server and client infrastructure needs to be regarded as software development, with repositories of self-documenting, tried-and-true, and executable solutions capable of maintaining an organization despite staffing changes.

Along with being a great player in automation, DevOps, and systems administration, it is beneficial to everyday users too. Ansible can be configured on a whole network of computers at once rather than just one computer; for doing that, no programming skills are required. Humans can read the instructions written for Ansible, and an entirely new computer user or expert can easily understand Ansible files.

What Does Cross-Platform Mean in Ansible?

A cross-platform computer system or an item functions in various operating systems or platforms.

Systems that require separate versions for each platform, systems that work the same way across several platforms, and other more general systems are all examples of different cross-platform systems.

Cross-platform can also be said as multi-platform or platform independent.

Ansible Highlights

Development

Michael DeHaan, the author of the provisioning server application Cobbler and co-author of the Fedora Unified Network Controller (Func) framework for remote administration, developed the Ansible tool, open-source software, in 2012, and Red Hat acquired it in 2015.

Derivation of Name

Ursula K. Le Guin, an American author, coined the term “ansible” to narrate fictitious instantaneous communication systems in her 1966 novel Rocannon’s World.

Aim

The aim of developing Ansible was to simplify real-world server automation problems.

Versions

Ansible versions get released in 4 to 6 months, depending upon the changes from version to version. As a standard operating procedure, each version is tested before its release. All Ansible versions are shown below:

Before 1.9

1.9 (1.9.1 to 1.9.6)

2.0 (2.0.1 to 2.0.3)

2.1 (2.1.1 to 2.1.6)

2.2 (2.2.1 to 2.2.4)

2.3 (2.3.1 to 2.3.4)

2.4 (2.4.1 to 2.4.7)

2.5 (2.5.1 to 2.5.15)

2.6 (2.6.1 to 2.6.20)

2.7 (2.7.1 to 2.7.16)

2.8 (2.8.1 to 2.8.8)

2.9 (2.9.1 to 2.9.4)

Initial version Before 1.9 was started as a project. The latest available version of Ansible is 2.9. This version was generally available on 6 Nov 2019; its end of life is 31 Dec 2021.

What Does Ansible Do?

Though the term Ansible modules give a sense of complexity, Ansible handles most of the complexity, and the user is not involved in it.

A module is written in such a way that it represents the desired state of a system, meaning that each module can define what should be the actual conditions on any given managed node.

For example, in an organization, if a system administrator decides that all the workstations should run on LibreOffice version X.Z., then at this moment, Ansible comes into action. Its packaging modules start checking to confirm the current state of the workstations, and when it finds that some nodes are running on LibreOffice X.Y., it is upgraded to LibreOffice version X.Z. Likewise, any workstation in an organization is upgraded a night with the help of the software.

How Does Ansible Work?

There are mainly two computer categories in Ansible: the managed node and the control node.

The control node, a computer, is responsible for running Ansible. At least one control node should be there; a backup control node may also exist in parallel. A managed node can be any device managed by the control node.

Ansible’s standard operating procedure is that it first gets connected to nodes such as servers, clients, or anything that needs to be configured and then sends a small program known as the Ansible module to that node. Then these modules are executed by Ansible over SSH, which is removed when the execution is completed.

The important thing for this interaction is that Ansible control nodes must have login access to the managed nodes. The SSH keys provide this access, and other forms of authentication also provide helping hands.

Disadvantages of Ansible

There are some disadvantages of Ansible that create some setbacks among the users. Let’s see them one by one:

1. Insufficient User Interface

  • Unsuccessful synchronization between the GUI and the command line results in conflicting query results. 
  • Ansible Tower is still in development and unable to do everything like a command-line interface.

2. Lack Of Any Notion of State

  • In contrast to other automation tools like Puppet, Ansible does not offer any concept of state.
  • Ansible cannot keep track of dependencies; instead, it merely conducts sequential tasks and comes to an end when they are finished, fails, or encounter any errors.

3. Limited Windows Support

  • The limited support for Windows in Ansible creates formidable setbacks with the configuration management and automation tool.

4. Ansible Does Not Have Experience

  • Less enterprise support experience also shrinks the appeal of Ansible. 
  • Lack of full-fledged working experience with large enterprises like its competitors, such as Puppet and Chef (Read: Chef vs Puppet). 

5. Ansible Is New To The Market

  • Unlike its renowned competitors, being new to the market results in a lack of a prominent developer or user community. 
  • Since Ansible is new to the market, there is a possibility of undiscovered bugs, software issues, and edge scenarios.

Ansible – Roles

Roles in Ansible provide a framework for collections of variables, files, tasks, modules, and templates that are independent or interdependent.

In Ansible, the role is a primary mechanism to break a playbook into multiple files. Ansible makes complex playbook writing simple and can be reused easily. The purpose of breaking the playbook is carried out so that it can be into reusable components.

Each role is assigned a particular functionality for desired output.

Roles are small functionality within playbooks that peak it can be independently used. In any conditions, you can not execute the role directly. 

Top-level playbooks are a bridge that holds the hosts from the user’s inventory file to roles that should apply to those hosts.

What Is An Ansible playbook?

The primary purpose of an Ansible module is to accomplish a specific task, and the way of utilizing them is through an Ansible playbook. An Ansible playbook can be defined as a configuration file written in YAML (Yet Another Markup Language) to provide instructions for things that need to be done to bring a managed node into the required state.

Humans and self-documenting easily read playbooks. They are also considered idempotent, meaning they can be run on a system anytime without hurting it.

If a playbook is run on a system, like adequately configured and in its desired state, then that system gets configured properly after a playbook runs.

A playbook can be straightforward. For example, look at this that installs as a privileged user, the Apache HTTP server, on any node in an I.T. department’s web servers group:

——————————————

Name: Apache server installed

hosts: web servers

become: yes

——————————————

With conditionals and variables, Playbooks can also be very complex types. As Ansible modules perform most primary work, playbooks remain brief, readable, and clear even though they manage entire networks of managed nodes.

Ansible – YAML Basics

In Ansible, YAML syntax is used for the expression of Ansible playbooks. Let’s have an overview of YAML. Ansible uses YAML because humans can easily understand, read and write it compared to other data formats such as XML and JSON.

All the YAML files will generally start with “—” and end with “…”.

Understanding YAML

This section is meant to teach the different ways in which the YAML data is represented.

key-value pair

In YAML, a simple key-value pair is used for the data representation.

Note: Keep space between: and value.

Example: A student record

Abbreviation

Abbreviations can also be used for the representation of dictionaries.

Example

James carter: {name: james carter, rollNo: 44, div: D, sex: male

Representing List

YAML allows representation of the List. Every element(member) of the List is to be written in a new line with the same indentation starting with “-“(-and space).

Example

countries:

America

China

Canada

Iceland

List inside Dictionaries

The List inside dictionaries can be used in YAML, i.e., the value of the key is a list.

Example

       James:

             name: James carter

             rollNo: 44

             div: D

             sex: male

             Likes:

     -chemistry

     -physics

                 -maths

      ……

List Of Dictionaries

A list of dictionaries can also be made.

Example

   James:

             name: James carter

             rollNo: 44

_________________________

             div: D

             sex: male

             Likes:

                 -chemistry

                 -physics

                 -maths

        Peter:

             name: peter

             rollNo: 20

             div: E

             sex: male

             Likes:

                 -English

                 -physics

                 -maths

_________________________

The Different YAML Tags

Let us understand the different YAML tags. The different tags are explained below:

name

The use of this tag to specify the name of the Ansible playbook. As per the role of the playbook, any logical name can be given to the playbook.

hosts

The use of this tag is to specify the lists of hosts or host groups against which the task is to be run. The hosts’ field/tag is mandatory and informs Ansible which hosts the listed tasks to be run. The tasks can either be run on the same machine or a remote machine. One can run the tasks on multiple machines, and the tag should also have a group of hosts’ entries for that host.

vars

The use of the Vars tag is to define the variables to use in the playbook. Usage variables in the same way as in any other programming language.

tasks

All playbooks should have tasks or a list of tasks that are required to be executed. Tasks are a list of actions that need to be performed. The task name is contained in a task field, which works as a helping text to the user. However, it is not mandatory but is helpful while debugging the playbook. Each task is linked internally to a piece of code called a module. 

It is to be noted that arguments must be mentioned to execute a module.

Common Playbook Issues

This section summaries a few common playbook issues that are as follows:

  • Quoting
  • Indentation

The playbook is written in YAML format, and the above two are considered the most common issues in the YAML/playbook.

Both tabs-based indentation and supported space-based indentation are not supported by YAML, so while writing syntax, one should be careful about the same.

Ansible – Troubleshooting

The following modules are considered very useful, practical, and the most common strategy for debugging Ansible playbooks:

Debug and Register

These two modules available in Ansible are handy for debugging purposes and should be used judiciously. 

Use Verbosity

Ansible command is used to provide the verbosity level. Run the command with verbosity level one (-v) or two (-Vv).

Conclusion

As a last thought, we conclude that Ansible exists to offer a straightforward and effective package for configuration management and automation. Being new to the software application market, Ansible faces tough competition from renowned sources. The availability of a limited amount of Ansible-related documentation creates setbacks for learning Ansible.

On a positive note, a growing interest can be seen in Ansible due to its adoption by NASA. The potentiality of Ansible can be described by its functionalities such as provisioning, application, orchestration, deployment, and security and compliance. 

Ansible’s benefits could be strengthened while the disadvantages are being addressed; by achieving this, a promising future for Ansible can be foreseen.

In this article, we have tried our best to cover as maximum as possible important aspects of Ansible to make you aware of this technology in the best possible way.

Frequently Asked Questions

How To Learn Ansible? Ansible can be learned by using it at home or work. For someone new to YAML (a human-readable data serialization language & commonly used for configuration files but could be used in many applications where data is being stored), it is advised to take some time learning it and then only write the first playbook.

On a small scale, it can be installed on a personal computer and used to manage itself or just a few computers on a home network. 

To be comfortable using and configuring new modules, it is a crucial recommendation to try different modules.

These are sources to make nodes conform to an infrastructure design, and Ansible is the engine that can make it possible.

Is Ansible Difficult To Learn? Getting familiar with Ansible hardly takes a week for a beginner level, so no prerequisites are required. Suppose someone has Linux operating system knowledge, especially in administration, experience, and visualization. In that case, less than one week is enough to know what Ansible is and how it operates practically.

→ Explore this Curated Program for You ←

Avatar photo
Great Learning Editorial Team
The Great Learning Editorial Staff includes a dynamic team of subject matter experts, instructors, and education professionals who combine their deep industry knowledge with innovative teaching methods. Their mission is to provide learners with the skills and insights needed to excel in their careers, whether through upskilling, reskilling, or transitioning into new fields.

Full Stack Software Development Course from UT Austin

Learn full-stack development and build modern web applications through hands-on projects. Earn a certificate from UT Austin to enhance your career in tech.

4.8 ★ Ratings

Course Duration : 28 Weeks

Cloud Computing PG Program by Great Lakes

Enroll in India's top-rated Cloud Program for comprehensive learning. Earn a prestigious certificate and become proficient in 120+ cloud services. Access live mentorship and dedicated career support.

4.62 ★ (2,760 Ratings)

Course Duration : 8 months

Scroll to Top