Ansible & its Use Case

Ansible & its Use Case

Imagine there are thousands of servers and you have to configure all of the servers manually means you have to install/uninstall/update any software, run/stop a program, or modify files & directories from no. of systems. these are the basic tasks IT professionals have to perform regular basis. performing these tasks manually will take a lot of time and is more error-prone. So, we can automate that repeating manual part. This is the reason ansible comes into the picture.

What is Ansible

Ansible is an open-source software provisioning, configuration management, and application-deployment tool enabling infrastructure as code.

It runs on many Unix-like systems and can configure both Unix-like systems as well as Microsoft Windows.

Ansible allows you to configure multiple nodes at one time from one single controller (Controller Node)using Infrastructure as code. The server which has ansible installed is known as the Controller node while the remote hosts/servers which are configured are known as Managed nodes.

3.png

The nicest part about Ansible is that it is Agentless, which means you don't have to install any software on the managed nodes or hosts. All that is required is ssh connectivity on the managed node. Although there are alternative options for connecting to managed hosts, ssh is the preferred method.

Why Ansible

Ansible uses Declarative language which means you just need to tell it What to do and not How to do it. Ansible uses RAL underline which stands for Resource Abstraction Layer which means you can configure the target systems without worrying about the implementation details and the other internal working.

Which makes Ansible Intelligent we can say

Ansible is a combination of both Automation and Intelligence.

Imperative & Declarative Language

12.png

In Imperative language, you need to specify

  • WHAT TO DO → eg. Which software to install?
  • HOW TO DO → eg. How to install that software?

For example, we want to install HTTPD software on rhel/ubuntu we need to use the exact command which rhel/ubuntu uses "yum install httpd" and for windows the command is different.

NOTE- in imperative language If you don’t know the Operating System's respective commands then it’s impossible to do any configuration.

In Declarative language, you only need to specify

  • WHAT TO DO → Which software to install?

we don't need to specify HOW TO DO it in Ansible. Whether it be Windows, Linux, or MAC we just have to write the code and Ansible is intelligent enough to detect the base OS and configure the systems using the respective commands.

In ansible, you have two approaches to configure things:-

  1. Ad-hoc commands (Command-line)
  2. Playbooks

Ad-hoc Commands: An Ansible ad hoc command uses the command-line tool to automate a single task on one or more managed nodes. ad hoc commands are quick and easy, but they are not reusable.

In playbooks, we write everything that needs to be configured on remote servers known as tasks. The playbook contains three things:-

  1. Hosts - IPs of managed nodes
  2. Name of the play
  3. Tasks - tasks to be performed on managed nodes

The format used for writing playbooks is YAML (Yet another markup language).

The remote servers or hosts which need to be configured are mentioned in the Inventory. There are two types of inventory:-

  1. Static Inventory
  2. Dynamic Inventory

We use dynamic inventory if our hosts are running on top of the cloud or in a container engine where the hosts scale up and down frequently.

The Ansible's magic is in its Modules. Ansible now has over 750 modules for practically everything, including cloud configuration, network device configuration, and container configuration. It's because Ansible is an open-source project with a strong community behind it.

Now let's summarise everything we've learned so far regarding Ansible:-

  • Agentless
  • Declarative language
  • Inventory
  • Modules
  • Simple to learn

So now that we know a little about Ansible, let's see some of the Industry use cases for Ansible.

Use case of Ansible

  1. PROVISIONING: Suppose you have a web app that you need to deploy and you need the environment for that so Ansible can provision environments for you on various platforms like Public Cloud, Private Cloud, and even Baremetal.
  2. Configuration management: The Ansible is mainly used for configuration management. In companies, you need to configure the servers daily to Perform a wide variety of configuration tasks, such as start/ stop services, changing the configuration of a system, device, or application, hosting the website, etc. So, ansible can configure your servers as per requirement and start the services for you with just one click.
  3. Firewall configuration: With ansible, you can create firewall rules and apply them to multiple hosts to make sure that your servers are secure and only required ports are open and listening.
  4. Application deployment: With ansible, you can automate the process of application deployment easily and fastly.

There are hundreds of other use cases that ansible can help you with, but these are the most popular ones. So, I hope this blog helped you understand what ansible is and some of the problems it solves for us.

Thanks for reading! I hope you understood these concepts and learnt something.

If you have any queries feel free to reach out to me on Linkedin

Did you find this article valuable?

Support Ritik Gupta by becoming a sponsor. Any amount is appreciated!