Ansible Training for Beginners

Ansible has taken over Puppet and Chef as one of the leading cloud configuration management tools, and its popularity is no surprise. As organizations worldwide embrace the cloud, the need for configuration management tools has shot up. As a result, Ansible Certification courses are selling like hotcakes as the demand for Ansible developers and Ansible automation engineers skyrocket.  A simple and powerful tool, Ansible simplifies IT automation and DevOps efforts. Thus, it’s an excellent resource for automating and configuring your infrastructure while saving time and increasing productivity. 

So, let’s dive in to learn more about Ansible and its basics for beginners.

What is Ansible?

Ansible is an automation and orchestration tool used for configuration management, intra-service orchestration, cloud provisioning, and application deployment. It is open source and was developed by Michael DeHaan in 2012.

Easy to install and deploy with no extra custom security infrastructure, Ansible can run on Windows and Unix-like operating systems. What’s more, it has its own simple declarative programming language (YAML) for management and system configuration. In addition, Ansible can seamlessly connect with cloud platforms like Microsoft Azure and Amazon AWS to make infrastructure management, automation, and code deployment a cakewalk.

Ansible for Beginners

Undoubtedly, Ansible is currently one of the most popular automation and configuration management tools on the market. It is the tool of choice for DevOps for its sheer ability to provide flexibility and streamline automation. However, if you’re thinking of getting the much sought-after Ansible Certification, check out this beginner’s guide first.

Tasks that Ansible automates

Following are the tasks that the IT engine automates:

  • Orchestration: It is the automated configuration, coordination, and management of applications, computer systems, and services. 
  • Configuration Management: It means that all the servers, computer systems, and software are maintained at a desired and consistent state.
  • Deployment: Ansible automates application deployment (moving software between testing and production environments) onto servers with different environments after regular intervals or at a specific time.

Why use Ansible?

A company’s infrastructure is pretty extensive, comprising all its systems, including database servers, web servers, etc. Hence, the system administrator must ensure that all systems are running the most up-to-date software versions. However, doing this task manually, especially in a large organization, is quite challenging. Moreover, it is bound to result in errors and inefficiencies. That’s where Ansible comes into the picture – to automate the entire configuration and deployment process of the systems.

Ansible basics

Having talked about what Ansible can do for organizations, it becomes pertinent to understand some key terms. 

  • Ansible has two primary components – the local machine and the client machine (node).
  • The system administrator installs Ansible in the local machine. On the other end is the node or the systems that require configuration. The node has no supporting software, and the local machine completely controls them.
  • The local machine uses a secure shell (SSH) to communicate with the node. There’s also a module or collection of configuration files (playbooks) written in YAML (Yet Another Markup Language). Playbooks are where instructions are created to determine the tasks that need execution.
  • The Ansible server is where you install Ansible, and the hosts are the machines that Ansible handles via the server. The Ansible server is capable of handling multiple hosts.
  • Modules are the set of commands for execution on the client side. 
  • A task is a section containing a single procedure that needs execution
  • Lastly,  there’s the inventory, a file containing client-server data or the nodes that need configuration. 

How Ansible works

The inventory and the playbooks are written on the local machine. The local machine then connects with the clients (nodes) via SSH. SSH keys simplify the entire process of connecting to the clients. 

Ansible works by pushing out modules to clients. After the modules execute locally on the client, the outputs get pushed back to the Ansible server. 

The next thing is the collection of facts or information about the current state of the node. Upon retrieval of facts from the node, it is sent to the local machine. As the playbook executes, the node’s current state is compared with the task listed in the playbook. Once further changes are made and the playbooks executed, the nodes are configured to the desired state.

Here is a simplified illustration of how Ansible works:

Getting started with Ansible

With the introductory Ansible concepts in mind, we’ll now walk you through two fundamental Ansible tools very briefly.  It’ll help you get a headstart before you sign up for an Ansible certification course.

Ansible Playbooks

Playbooks are the foundation of orchestrated automation and configuration management in Ansible. Each playbook comprises one or more plays, and each play defines a minimum of two things – the hosts you want to target and the tasks to execute. Playbooks are repeatable and reusable.

Plays begin by defining the hosts line, followed by a tasks list. Ansible orderly executes the tasks on the designated hosts, one at a time. 

Following is an example of a playbook:

The above example shows the execution of three plays – deploying code to the web servers, updating the database schema, and checking the app status page.

Ad-hoc commands

Ad-hoc commands are used for the automation of a single task on one or more hosts. Unlike playbooks, ad-hoc commands are not reusable. They are suitable for infrequent tasks such as rebooting servers, testing connectivity, managing files and services, or gathering facts.

Following are different ad-hoc commands and their functions:

  • ping: Connectivity testing
  • file: Adding/removing directories
  • stat: Retrieving facts about directories
  • copy: Copying files
  • debug: Debugging expressions and variables
  • Replace: Updating files
  • Lookup: Plugin for accessing data from external sources

Here’s an example to show how the stat command looks:

Conclusion

Did you know that 31% of the current usage share belongs to Ansible among popular cloud configuration tools used worldwide? 

With a number of benefits like high customizability, flexibility, reliable deployments, automated reporting, security, and agentless abilities, Ansible is undoubtedly the most trending tool for modern DevOps environments. What’s more, it has a smooth learning curve and has a wide variety of applications in DevOps and cloud computing areas. With the basics within your grasp, you can explore advanced topics such as Ansible inventories, roles, containers, and more. 

Leave a Reply

Your email address will not be published.