Getting Started with Ansible: A Beginner’s Perspective.

Getting Started with Ansible: A Beginner's Perspective.

Ansible is a suite of software tools, that simplifies IT tasks like configuration management, application deployment, provisioning, and orchestration. It allows users to define the desired state of their infrastructure and applications in code, known as “Infrastructure as Code” (IaC).

Introduction.

Ansible is an open-source automation tool, that enables cross-platform automation and orchestration at scale and has become over the years the standard choice among enterprise automation solutions. Ansible uses YAML files as its main source of information at run time. YAML is a data representation language that is commonly used for configuration. It is ease of installation, client connection, absence of agent, and large skill set make it a favorite. Ansible works with Linux, Windows, cloud platforms, network devices, and more.

How does Ansible work.

Ansible uses the concepts of control and managed nodes.

Controller Node: The machine where Ansible is installed and from which commands or playbooks are executed. This is the “control center.”

Managed Nodes: The systems or devices Ansible manages (e.g., servers, network devices, cloud instances). These nodes don’t require Ansible to be installed, as Ansible is agentless.

Modules: The units of code that Ansible executes on the managed nodes are called modules.

Playbooks: YAML files that define the tasks and the desired state of the system.

Inventory File: A file (in INI or YAML format) listing the managed nodes. It specifies groups, hostnames, IP addresses, and variables for target systems.

Benefits of using Ansible.

  • Reduces overhead, simplifies system maintenance, and eliminates potential agent-related security risks.
  • Includes some sophisticated features around modularity and reusability that come in handy as users become more proficient.
  • A free and open-source community project with a huge audience.
  • Ansible can manage a wide range of systems, including Linux, Windows, network devices, containers, and cloud platforms (AWS, Azure, GCP).
  • Ansible is free to use under the GNU General Public License.

The Architecture of Ansible.

Modules.

Modules are discrete units of code that perform specific tasks on managed nodes. The library of modules can exist on any machine without the need for servers, databases, or daemons. Ansible gives much-needed flexibility for scripting your modules. 

Plugins.

Plugins are also one of the common entries in the architecture of ansible found commonly in every ansible documentation. Plugins extend Ansible’s core functionality. Python is the sole language for writing ansible plugins.

Inventory.

Inventories can be static (a simple file with hostnames) or dynamic (integrating with cloud APIs or other external systems). Ansible provides a representation of machines that it manages in a file which is responsible for putting all the managed machines. 

Configuration File (ansible.cfg).

The configuration file customizes Ansible’s behavior, such as specifying the inventory file path, default SSH user, or timeout settings.

How to Install Ansible.

Ubuntu uses the APT package manager to install applications. Run the following commands to install Ansible on any Ubuntu Linux.

sudo apt update && sudo apt upgrade -y
sudo apt install software-properties-common

sudo add-apt-repository --yes --update ppa:ansible/ansible

#install ansible:
sudo apt install ansible -y

#Validate Ansible:
ansible --version
            

Ansible inventory.

The Ansible inventory is a file or system that lists the hosts and groups of hosts that Ansible manages. It serves as a source of truth for Ansible to know where tasks should be executed.  On the Ansible server, Ansible is installed, and when it communicates with hosts running Linux or Windows, it uses ssh for Linux and powershell for Windows. The inventory system is highly flexible and adaptable, allowing Ansible to manage both small, static environments and large, dynamic infrastructures effectively.

[webservers]
web1.example.com
web2.example.com

[databases]
db1.example.com
db2.example.com

Ansible Playbooks.

Automation tasks, or “playbooks,” are detailed plans for carrying out complicated IT operations with minimal to no intervention from a human operator. It’s is a YAML file that defines a set of tasks to automate processes on managed nodes. Ansible playbooks make automation simple, readable, and scalable across any IT environment.

Conclusion.

In conclusion, Ansible is a powerful, flexible, and easy-to-use automation tool that simplifies IT operations and infrastructure management. It handles environments of all sizes, from small setups to enterprise-grade infrastructures. Ansible is more than just a tool—it’s a framework for building reliable and efficient IT processes. By embracing Ansible, organizations can achieve greater agility, improve collaboration, and stay ahead in the fast-evolving world of IT and DevOps.

shamitha
shamitha
Leave Comment